AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 456694
Accepted
yael
yael
Asked: 2012-12-11 03:00:55 +0800 CST2012-12-11 03:00:55 +0800 CST 2012-12-11 03:00:55 +0800 CST

根据主机名规则在文件中进行 Linux/Solaris 验证(主机名更改后)

  • 772

根据以下 Perl 命令

(此命令是 ksh 脚本的一部分)

我可以在 Linux 或 Solaris 中用新主机名替换旧主机名

 previos_machine_name=linux1a
 new_machine_name=Red_Hat_linux1a

 export previos_machine_name
 export new_machine_name

.

      perl -i -pe 'next if /^ *#/; s/(\b|[[:^alnum:]])$ENV{previos_machine_name}(\b|[[:^alnum:]])/$1$ENV{new_machine_name}$2/g'  file

解释:根据 perl 命令 - 我们不会在以下情况下替换主机名:

规则: [数字]||[字母]主机名[数字]||[字母]

我的问题

在我使用 Perl 命令以根据 Perl 命令中的“RULE”将所有旧主机名替换为新主机名之后

如何验证文件中不存在旧主机名?

例如

   previos_machine_name=linux1a

   new_machine_name=Red_Hat_linux1a

   more file

   AAARed_Hat_linux1a          verification should be ignore from this line
   @Red_Hat_linux1a$             verification should be match this line
   P=Red_Hat_linux1a            verification should be match this line
   XXXRed_Hat_linux1aZZZ         verification should be ignore from this line
   .
   .
   .
   .
linux
  • 1 1 个回答
  • 125 Views

1 个回答

  • Voted
  1. Best Answer
    John Siu
    2012-12-11T05:35:40+08:002012-12-11T05:35:40+08:00

    使用 fowling line 打印匹配字符串

    perl -i -pe 'next if /^ *#/; if ($_ =~ /(\b|[[:^alnum:]])$ENV{previos_machine_name}(\b|[[:^alnum:]])/) { print STDOUT $_; }'  file
    

    如果它打印出空的,那意味着不存在旧的主机名。

    • 0

相关问题

  • Linux 主机到主机迁移

  • 如何在 Linux 机器上找到有关硬件的详细信息?

  • 如何在 Linux 下监控每个进程的网络 I/O 使用情况?

  • 在 RHEL4 上修改 CUPS 中的现有打印机设置

  • 为本地网络中的名称解析添加自定义 dns 条目

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve