1833785 Members
2871 Online
110063 Solutions
New Discussion

help with script

 
SOLVED
Go to solution
Jairo Campana
Trusted Contributor

help with script

hello, I have a file and I want to insert a word at the beginning example

cat file1
john
carl

I want to insert the word hello
obtaing:
cat file1
hello john
hello carl
hello ...
hello ...
....
..

legionx
7 REPLIES 7
James R. Ferguson
Acclaimed Contributor

Re: help with script

Hi:

# sed -n 's/^/hello /p' file1

Regards!

...JRF...
Jeff_Traigle
Honored Contributor

Re: help with script

One way among many...


ed file1 <1,\$s/^/hello /g
w
q
EOC
--
Jeff Traigle
A. Clay Stephenson
Acclaimed Contributor

Re: help with script

and still another:

cat file1 | while read X
do
echo "hello ${X}"
done
If it ain't broke, I can fix that.
James R. Ferguson
Acclaimed Contributor
Solution

Re: help with script

Hi (again):

Yet another, which updates your file "inplace" is:

# perl -pi -e 's/^/hello /' file1

Regards!

...JRF...
Jairo Campana
Trusted Contributor

Re: help with script

Clay , I change "${X}" for $X
with "{}" no working in the while.

and still another:

cat file1 | while read X
do
echo "hello $X"
done

thanks to all for the aid
legionx
Sandman!
Honored Contributor

Re: help with script

awk '{print "hello "$0}' file1
Jairo Campana
Trusted Contributor

Re: help with script

the perl this is a best option .
legionx