简体   繁体   English

使用sed / awk /替换匹配的列

[英]replacing matching columns using sed/awk/

How can I achieve this using awk/sed or any other scripting commands. 如何使用awk / sed或任何其他脚本命令实现此目的。

1) Read a file with many rows containing 26 digits in each line 2)Using shell scripting replace 07 with 08 only in 25th and 26th column of each row if 07 is found 1)读取每行包含26位数的行的文件2)使用shell脚本如果找到07,则仅在每行的第25和第26列中替换07和08

Thankyou. 谢谢。

awk

awk  'BEGIN{FS=""; OFS=""}{if ($25$26 == "07") {$25="0"; $26="8"}{print}}'

if you are sure each row in your file has 26 digits. 如果您确定文件中的每一行都有26位数字。 (length 26), you could: (长度26),你可以:

sed 's/07$/08/' file

这可能适合你(GNU sed):

sed -r 's/^(.{24})07/\108/' file

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM