zulabc
October 18, 2011, 10:40pm
1
I have several file as below, and i want to put .txt to specific text contain ^main=EXE^cmd=run script /usr/prog/bd_,
file1
7.9102 12.1528 16.3672 7.4002
^main=EXE^cmd=run script /usr/prog/bd_123^"
line 16.3672 7.3134 17.8711 6.0981
file 2
7.9102 12.1528 16.3672 7.4002
^main=EXE^cmd=run script /usr/prog/bd_148^"
5.6836 17.5998 19.3566 15.5998
file 3
1.10001
^main=EXE^cmd=run script /usr/prog/bd_165^"
1.10001.888.20.3
I want my output file
file1
7.9102 12.1528 16.3672 7.4002
^main=EXE^cmd=run script /usr/prog/bd_123.txt^"
line 16.3672 7.3134 17.8711 6.0981
file 2
7.9102 12.1528 16.3672 7.4002
^main=EXE^cmd=run script /usr/prog/bd_148.txt^"
5.6836 17.5998 19.3566 15.5998
file 3
1.10001
^main=EXE^cmd=run script /usr/prog/bd_165.txt^"
1.10001.888.20.3
rdcwayx
October 18, 2011, 10:50pm
2
I saw the same topic already, looks like a homework.
zulabc
October 18, 2011, 10:53pm
3
please help me
---------- Post updated at 09:53 PM ---------- Previous update was at 09:52 PM ----------
please help me
zulabc
October 19, 2011, 12:06am
5
rangarasan:
Hi,
Try this one,
sed 's/$/addstr/g' file
Cheers,
Ranga:-)
thanks for help but using this code will put .txt all of the end of line..i want to put the .txt in the specific line
Hi,
you can use awk to match the pattern and add the string at the end of line,
awk 'BEGIN{OFS="";}$0 !~ /pattern/{print;}$0 ~ /pattern/{print $0,"addstr";}' input_file
here,
pattern must be same in two regex.
addstr - going to append in the end of line.
Cheers,
Ranga:)
See if this sed fills your requirement
"s#\^main=EXE\^cmd=run script /usr/prog/[Aa-Zz]\{1,5\}_[0-9]\{1,5\}#&.txt#g" file > outfile
It will match a line containing <first part> /usr/prog<any 1 to 5 letters> followed by an underscore and <any 1 to 5 numbers >.
$ sed 's,\^\"$,.txt\^\",g' infile
zulabc
October 20, 2011, 4:21am
9
peasant:
See if this sed fills your requirement
"s#\^main=EXE\^cmd=run script /usr/prog/[Aa-Zz]\{1,5\}_[0-9]\{1,5\}#&.txt#g" file > outfile
It will match a line containing <first part> /usr/prog<any 1 to 5 letters> followed by an underscore and <any 1 to 5 numbers >.
thanks for the code and its work fine and return what i want..the problem is
I'm using the for do loop so the output will print end of the line multiple .txt
is it any possibility to use "if condition"
for example
if
blah.txt
exit
fi
help...