Operating System - HP-UX
1833041 Members
2385 Online
110049 Solutions
New Discussion

Insert text at the beginning of every line of a log file.

 
SOLVED
Go to solution
Adam Prince
Occasional Contributor

Insert text at the beginning of every line of a log file.

G'day all,
I have a logfile and I would like to insert text and the beginning of every line. I am pretty sure I use sed but I can seem to get the syntax right. Any help would be greatly appericated. Merry Xmas to all.
5 REPLIES 5
Andreas Voss
Honored Contributor
Solution

Re: Insert text at the beginning of every line of a log file.

Hi,

try this:

sed -e 's/^/your_text/' file > file1

Regards
Robin Wakefield
Honored Contributor

Re: Insert text at the beginning of every line of a log file.

Hi Adam,

With perl, you can also do an in-line edit:

perl -pi -e 'print "your_text"' logfile

Rgds, Robin.
S.K. Chan
Honored Contributor

Re: Insert text at the beginning of every line of a log file.

# sed 's/^/hello /g' fileA > fileB

==> will insert text "hello "
Craig Rants
Honored Contributor

Re: Insert text at the beginning of every line of a log file.

Andreas answer is better than the a append or i insert options of sed. I would go with that sed option for easy of use.

HH,
C
"In theory, there is no difference between theory and practice. But, in practice, there is. " Jan L.A. van de Snepscheut
Adam Prince
Occasional Contributor

Re: Insert text at the beginning of every line of a log file.

Thanks for the help.
This forum is excellent, I always get the help I need.
Thanks again.