Error[8]: Undefined offset: 2, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述有人可以帮我解决这个问题吗?我正在寻找一个SED或AWK命令,我可以用它在配置文件( Linux)中找到一个唯一的字符串,上一行并在该行的末尾添加一个字符串? 例如: 配置文件: define hostgroup{ hostgroup_name http-urls ; The name of the hostgroup alias HTTP URLs ; Long name of the grou 有人可以帮我解决这个问题吗?我正在寻找一个SED或AWK命令,我可以用它在配置文件( Linux)中找到一个唯一的字符串,上一行并在该行的末尾添加一个字符串?

例如:

配置文件:

define hostgroup{
hostgroup_name http-urls ; The name of the hostgroup
alias http URLs ; Long name of the group
members domain1.com,domain2.com,domain3.com,
#MyUniqueString
}

在上面的例子中,我想使用SED或AWK来查找#MyUniqeString,上一行以成员开头,并在行尾添加“domain4.com”.

我在下面发现了这个问题,但我需要首先搜索文本文件中的字符串,然后在上面找一行.

Bash script: Appending text at the last character of specific line of a file

有什么建议?

解决方法 试试这个单行:

awk '{a[NR]=
kent$ cat test.txt define hostgroup{hostgroup_name http-urls ; The name of the hostgroupalias http URLs ; Long name of the groupmembers domain1.com,#MyUniqueString}kent$ awk '{a[NR]=[+++]}/#MyUniqueString/{a[NR-1]=a[NR-1]"domain4.com"}END{for(i=1;i<=NR;i++)print a[i]}' test.txt define hostgroup{hostgroup_name http-urls ; The name of the hostgroupalias http URLs ; Long name of the groupmembers domain1.com,domain4.com#MyUniqueString}
}/#MyUniqueString/{a[NR-1]=a[NR-1]"domain4.com"}END{for(i=1;i<=NR;i++)print a[i]}' configfile

测试

[+++] 总结

以上是内存溢出为你收集整理的linux – 在文件中查找唯一的字符串,在一行中添加并追加?全部内容,希望文章能够帮你解决linux – 在文件中查找唯一的字符串,在一行中添加并追加?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 3, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述有人可以帮我解决这个问题吗?我正在寻找一个SED或AWK命令,我可以用它在配置文件( Linux)中找到一个唯一的字符串,上一行并在该行的末尾添加一个字符串? 例如: 配置文件: define hostgroup{ hostgroup_name http-urls ; The name of the hostgroup alias HTTP URLs ; Long name of the grou 有人可以帮我解决这个问题吗?我正在寻找一个SED或AWK命令,我可以用它在配置文件( Linux)中找到一个唯一的字符串,上一行并在该行的末尾添加一个字符串?

例如:

配置文件:

define hostgroup{
hostgroup_name http-urls ; The name of the hostgroup
alias http URLs ; Long name of the group
members domain1.com,domain2.com,domain3.com,
#MyUniqueString
}

在上面的例子中,我想使用SED或AWK来查找#MyUniqeString,上一行以成员开头,并在行尾添加“domain4.com”.

我在下面发现了这个问题,但我需要首先搜索文本文件中的字符串,然后在上面找一行.

Bash script: Appending text at the last character of specific line of a file

有什么建议?

解决方法 试试这个单行:

awk '{a[NR]=
kent$ cat test.txt define hostgroup{hostgroup_name http-urls ; The name of the hostgroupalias http URLs ; Long name of the groupmembers domain1.com,#MyUniqueString}kent$ awk '{a[NR]=}/#MyUniqueString/{a[NR-1]=a[NR-1]"domain4.com"}END{for(i=1;i<=NR;i++)print a[i]}' test.txt define hostgroup{hostgroup_name http-urls ; The name of the hostgroupalias http URLs ; Long name of the groupmembers domain1.com,domain4.com#MyUniqueString}
}/#MyUniqueString/{a[NR-1]=a[NR-1]"domain4.com"}END{for(i=1;i<=NR;i++)print a[i]}' configfile

测试

[+++] 总结

以上是内存溢出为你收集整理的linux – 在文件中查找唯一的字符串,在一行中添加并追加?全部内容,希望文章能够帮你解决linux – 在文件中查找唯一的字符串,在一行中添加并追加?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
linux – 在文件中查找唯一的字符串,在一行中添加并追加?_系统运维_内存溢出

linux – 在文件中查找唯一的字符串,在一行中添加并追加?

linux – 在文件中查找唯一的字符串,在一行中添加并追加?,第1张

概述有人可以帮我解决这个问题吗?我正在寻找一个SED或AWK命令,我可以用它在配置文件( Linux)中找到一个唯一的字符串,上一行并在该行的末尾添加一个字符串? 例如: 配置文件: define hostgroup{ hostgroup_name http-urls ; The name of the hostgroup alias HTTP URLs ; Long name of the grou 有人可以帮我解决这个问题吗?我正在寻找一个SED或AWK命令,我可以用它在配置文件( Linux)中找到一个唯一的字符串,上一行并在该行的末尾添加一个字符串?

例如:

配置文件:

define hostgroup{
hostgroup_name http-urls ; The name of the hostgroup
alias http URLs ; Long name of the group
members domain1.com,domain2.com,domain3.com,
#MyUniqueString
}

在上面的例子中,我想使用SED或AWK来查找#MyUniqeString,上一行以成员开头,并在行尾添加“domain4.com”.

我在下面发现了这个问题,但我需要首先搜索文本文件中的字符串,然后在上面找一行.

Bash script: Appending text at the last character of specific line of a file

有什么建议?

解决方法 试试这个单行:

awk '{a[NR]=
kent$ cat test.txt define hostgroup{hostgroup_name http-urls ; The name of the hostgroupalias http URLs ; Long name of the groupmembers domain1.com,#MyUniqueString}kent$ awk '{a[NR]=}/#MyUniqueString/{a[NR-1]=a[NR-1]"domain4.com"}END{for(i=1;i<=NR;i++)print a[i]}' test.txt define hostgroup{hostgroup_name http-urls ; The name of the hostgroupalias http URLs ; Long name of the groupmembers domain1.com,domain4.com#MyUniqueString}
}/#MyUniqueString/{a[NR-1]=a[NR-1]"domain4.com"}END{for(i=1;i<=NR;i++)print a[i]}' configfile

测试

总结

以上是内存溢出为你收集整理的linux – 在文件中查找唯一的字符串,在一行中添加并追加?全部内容,希望文章能够帮你解决linux – 在文件中查找唯一的字符串,在一行中添加并追加?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/1027875.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存