Operating System - HP-UX
1748259 Members
3645 Online
108760 Solutions
New Discussion юеВ

Re: append file with a string after a known string in file

 
SOLVED
Go to solution
Prashant Zanwar_4
Respected Contributor

append file with a string after a known string in file

Is this possible? how pls suggest.
Thnx
Prashant
"Intellect distinguishes between the possible and the impossible; reason distinguishes between the sensible and the senseless. Even the possible can be senseless."
2 REPLIES 2
Fred Ruffet
Honored Contributor
Solution

Re: append file with a string after a known string in file

in perl, insert "interresting" when data is found in a line :

/> cat inputFile
this
file
contains
some
data
in
it
/> perl -e < inputFile 'while () { ~m/data/g; if (pos) { print "interresting\n" } print }'
this
file
contains
some
interresting
data
in
it

Regards,

Fred
--

"Reality is just a point of view." (P. K. D.)
c_51
Trusted Contributor

Re: append file with a string after a known string in file

num=$(grep -c yourstring yourfile)
if (( $num > 0 )) ;then
print "appendthis" >> yourfile
fi