Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 将字符附加到特定行中的特定多列_Bash_Shell_Scripting_Sed_Awk - Fatal编程技术网

Bash 将字符附加到特定行中的特定多列

Bash 将字符附加到特定行中的特定多列,bash,shell,scripting,sed,awk,Bash,Shell,Scripting,Sed,Awk,我有一个文件,我想在特定行的多个特定列中添加特定字符。例如,我的文件是 shirts pants tshirts greet 100000 11111 1200000 131313 123456 15823 1542358 752256 我想在第二行(可能有多个列,未知)之后的所有列中添加一个字符,仅添加到第一行。我可以使用选择第一行和列 NR<2 and NF>2 awk'NR==1{x=$1”\t“$2;for(i=3;iawk'NR==1{x=$1”\t“$2;for(i

我有一个文件,我想在特定行的多个特定列中添加特定字符。例如,我的文件是

shirts pants tshirts greet 
100000 11111 1200000 131313
123456 15823 1542358 752256
我想在第二行(可能有多个列,未知)之后的所有列中添加一个字符,仅添加到第一行。我可以使用选择第一行和列

NR<2 and NF>2

awk'NR==1{x=$1”\t“$2;for(i=3;i
awk'NR==1{x=$1”\t“$2;for(i=3;i关于
NR2
的使用,您是对的。类似这样的解决方案:

$ awk 'NR==1{for (i=3; i<=NF; i++) $i="sold"$i}1' a
shirts pants soldtshirts soldgreet
100000 11111 1200000 131313
123456 15823 1542358 752256

$awk'NR==1{for(i=3;i关于使用
NR2
,您是对的。类似这样的解决方案:

$ awk 'NR==1{for (i=3; i<=NF; i++) $i="sold"$i}1' a
shirts pants soldtshirts soldgreet
100000 11111 1200000 131313
123456 15823 1542358 752256
$awk'NR==1{for(i=3;i这可能适合您(GNU-sed):

这可能适用于您(GNU-sed):

$ awk 'NR==1{for (i=3; i<=NF; i++) $i="sold"$i}1' a
shirts pants soldtshirts soldgreet
100000 11111 1200000 131313
123456 15823 1542358 752256
sed -i '1s/\S\+/sold&/3g' file