0

Basically i've been trying to figure out a way to take a four digit number from each line and paste it at the end of its line with the word pass in front. IE

take this file:

Home1234 10.10.10.1
Home1248 10.10.10.2 
Home0934 10.10.10.3 
Home0047 10.10.10.4  

And after should look like:

Home1234 10.10.10.1 pass1234
Home1248 10.10.10.2 pass1248
Home0934 10.10.10.3 pass0934
Home0047 10.10.10.4 pass0047
4

4 に答える 4

0

& を使用した別の sed バリエーション (一致したものすべてを貼り付けます):

sed -ie 's/^.*\([0-9]\{4\}\).*/& pass\1/' yourfile
于 2013-03-29T14:41:04.490 に答える
0

これで試すことができます:

awk '{a=substr($1,5,4); print $0" pass"a}' YOUR_FILE
  • substr($1,5,4)varから取得NNNNして格納するHomeNNNNa
  • print $0" pass"aすべての行と var を出力しますa

テキストが常にではなくHome、可変サイズで異なる場合は、次を使用できます。

awk '{a=substr($1,length($1)-3,4); print $0" pass"a}' YOUR_FILE
于 2013-03-29T11:04:29.880 に答える
0

あなたの問題はあまりよく定義されていません (次のような入力で何をしたいです1234 5678 3333 10.3.5.5か?) が、おそらく:

sed '/^\([^ ]*\([0-9]\{4\}\).*\)/s//\1 pass\2/' input
于 2013-03-29T12:01:39.673 に答える
0

この awk ワンライナーはあなたを助けるかもしれません:

awk '{n=substr($1,length($1)-3);$0=$0" pass"n}1' file
于 2013-03-29T11:05:47.293 に答える