We use awk here to build a sed-script and tac to reverse it so that we only have a single match:$ awk '(NR>1){print "s/"p"/"$1"/g"}{p=$1}' $file_names.txts/pfg022G/pfg022T/gs/pfg022T/pfg068T/gs/pfg068T/pfg130T/gs/pfg130T/pfg181G/gs/pfg181G/pfg181T/gs/pfg181T/pfg424G/gs/pfg424G/pfg424T/g如果使用上述脚本执行 sed ,我们将始终以 pfg424T (最后一个条目)结束,因为它将找到一个匹配项(假设我们是在第三个条目 pfg068T )中,因此sed将在此之后执行所有替换.但是,当我们颠倒顺序(使用 tac )时, sed 只会找到一个匹配项.If we do a sed with the above script, we will always end up with pfg424T (the last entry) as it will find a single match (assume we are in the third entry pfg068T), so sed will perform every substitution after that. However, when we reverse the order (using tac), sed will only find a single match. 这篇关于在crontab上创建一个命令流编辑器,并每15分钟重写一次文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-15 20:21
查看更多