Is there a unix command for this?

Is there a unix command to prefix a string of text to a long list of words saved in a text file in the following format:

word1
word2
word3

And add, for example, "blah" to the beginning of each word:

blahword1
blahword2
blahword3

And then save the final text file?

Thanks in advance!

awk '{sub(/^/,"blah");print;}' old.file > new.file
1 Like
cat <old file> |while read line
do
  echo "blah"$line >> newfile
done

Excellent, thanks so much!

Or

$ xargs -I{} echo blah{} < file1    
blahword1
blahword2
blahword3

You could edit the same file inplace with

sed -i "s/.*/blah&/" file1

or

ed file1 << EOF
1,$ s/.*/blah&/
w
q
EOF
ed file1 << EOF
1,$ s/.*/blah&/
w
q
EOF

[/quote]

That last one was just you showing off...

lolz