English 中文(简体)
Sed/Awk 对应/插入的文字?
原标题:Sed/Awk script to append/insert?

我有一个组合文件,像以下例子。 一系列定义按东道国名称分类。 我刚才将“技术服务”的定义添加到一个东道方的“母亲”。 现在,我需要在同一档案中做更多的工作。 我已经做过的事情从“汇案”中删除了所有先前的东道名称(100+)。 因此,现在我有一份服务器清单,现在需要确定服务的定义。 他们已经service,因此,我只想给他们增加服务。 显然,通过人工方式这样做是荒谬的。

是否有一只精细的文字,我可以用来做这类工作。 基本上,我需要写一份带有定义部分的kel子文件,并离开东道方——姓名空白。 然后向东道国提供食物。 file。 我也许会以大约六点trick子 this笑。 不确定吗?

提前感谢!

 
define{
        use                             cpu-service
        host_name                       mothership
        contact_groups                  systems manager
}
define{
        use                             ping-service
        host_name                       mothership
        contact_groups                  systems manager
}
问题回答

尽管我稍感想去做工作,但尝试以下文字:

 awk  
 BEGIN {
         RS = ORS = "}
"
         FS = "
"
 }
 NF > 0 {
         print
         if (sub(/ping-service/, "cpu-service")) print
 }
   file

一次性交易: 我有过“}”的痕迹,但除非你每天都要这样做,否则,这并不值得担忧。

∗∗∗∗∗ 如果贵供应商船舶具有历史版本awk 页: 1

三个步骤是错误的:

1. 人质姓名档案(姓名:txt)

mothership
motherload
motherofpeal
mothersbaugh

2. 文字(东道方sh)

#!/bin/bash

HOSTNAME=$1

TEMPLATE=" 
define{
        use                             cpu-service
        host_name                       ${HOSTNAME}
        contact_groups                  systems manager
}
define{
        use                             ping-service
        host_name                       ${HOSTNAME}
        contact_groups                  systems manager
}"

echo "${TEMPLATE}"

3) 指挥

chmod +x hostup.sh
while read name; do hostup.sh $name; done < hostnames.txt
while read name; do hostup.sh $name; done < hostnames.txt >> hosts.conf

安装后可插入新条线,紧靠背部,例如,在你的主机档案中将每一条线连接起来,代之以服务的全面定义。 我不敢肯定,这是你想要的。

sed -e  s/^(.*)$/define{
    use                             cpu-service
    host_name                       1
    contact_groups                  systems manager
}/g  hosts.txt > new_directives

if you re happy with new_directives then you can just

cat new_directives >> config_file





相关问题
Why does my chdir to a filehandle not work in Perl?

When I try a "chdir" with a filehandle as argument, "chdir" returns 0 and a pwd returns still the same directory. Should that be so? I tried this, because in the documentation to chdir I found: "...

How do I use GetOptions to get the default argument?

I ve read the doc for GetOptions but I can t seem to find what I need... (maybe I am blind) What I want to do is to parse command line like this myperlscript.pl -mode [sth] [inputfile] I can use ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...

热门标签