![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jun 2005
Posts: 2
Rep Power: 0
![]() |
Sed, insert string to the beginning of a line
Hello,
I would need to add a specific string to the beginning of every line in a document which contains an other specific string, by using Sed or Awk. I've tried my best to figure out this myself by using examples and tutorials, but I cant find any documentation about this. I did find out how to add something to the beginning of every line (s/^.*/text-to-add/ ), but I didn't manage to convert that so that it would work as i need it. Ie. If a line contains the string <AB>, i would like to add a the text 'CDE' to the very beginning of that same line. Im using Sed for Windows, but I asume the commands are almost the same as for Linux. Thank you in advance, Ken2 Last edited by Ken2; Jun 17th, 2005 at 3:20 PM. |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Jun 2005
Location: New Mexico
Posts: 228
Rep Power: 3
![]() |
awk solution:
awk ' {if(/AB/)
{ print "CDE" $0}
else
{print $0}
} ' filenameAB PDQ PLMAB CDEAB PDQ CDEPLMAB |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Jun 2005
Posts: 2
Rep Power: 0
![]() |
Thank you very much
![]() |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|