Lots of sed

Hi,

I have 200 lines of sed commands in a shellscript

sed s/TSTARTO2GPRSEVENTAPNACCSUM_1/TSTARTO2GPRSEVENTAPNACCSUM_24/g
sed s/O2GPRSEVENTAPNACCSUM_1/O2GPRSEVENTAPNACCSUM_24/g
sed s/TENDO2GPRSEVENTAPNACCSUM_1/TENDO2GPRSEVENTAPNACCSUM_24/g
sed s/BSTARTO2EVENTITEM_1/BSTARTO2EVENTITEM_24/g
sed s/1aBSTARTITEM_1/1aBSTARTITEM_24/g
sed s/RATINGTARIFF_1/RATINGTARIFF_24/g
sed s/BSTARTEVENTLIST_1/BSTARTEVENTLIST_24/g
sed s/EVSOURCE_1/EVSOURCE_24/g
sed s/EVENTSTEXT_1/EVENTSTEXT_24/g
sed s/EVSRCRATINGTARIFF_1/EVSRCRATINGTARIFF_24/g
sed s/ITEMISATIONORDER_1/ITEMISATIONORDER_24/g
sed s/ITEMISATIONMNY_1/ITEMISATIONMNY_24/g
sed s/EVENTLISTSTARTDAT_1/EVENTLISTSTARTDAT_24/g
sed s/EVENTLISTENDDAT_1/EVENTLISTENDDAT_24/g
sed s/1aTSTARTEVENT_1/1aTSTARTEVENT_24/g
sed s/1aEVENT_1/1aEVENT_24/g
sed s/TENDEVENT_1/TENDEVENT_24/g
sed s/EVTOTALITEM_1/EVTOTALITEM_24/g
sed s/EVCOMPTOTALITEM_1/EVCOMPTOTALITEM_24/g
sed s/EVINTTOTALITEM_1/EVINTTOTALITEM_24/g

Im just wondering how I apply all of these to one file at once. Im sure im missing something incredibly obvious but I just can't tell!

thanks in advance

Create a file with all your sed statements as:

s/TSTARTO2GPRSEVENTAPNACCSUM_1/TSTARTO2GPRSEVENTAPNACCSUM_24/g
s/O2GPRSEVENTAPNACCSUM_1/O2GPRSEVENTAPNACCSUM_24/g
...
s/EVCOMPTOTALITEM_1/EVCOMPTOTALITEM_24/g
s/EVINTTOTALITEM_1/EVINTTOTALITEM_24/g

Then run as:

sed -f sed_file Input_File
1 Like

not sure your real purpose, if you only need replace _1 to _24, maybe just

s/_1/_24/g

or maybe try this command to replace all of them.

sed "s/\([^ ]*\)_1/\1_24/g" infile
echo 123 | sed -n 's/1/2/g;s/2/3/gp'

I have tried using this one

sed -f sed_file Input_File

but it says it cannot be parsed

rdcwayx thanks but it has to be specific to these as there are _1 that I dont want replacing

To parse the file as a sed script, it needs to not contain the "sed " commands.

To use this method, first create a sed script file from those lines using

sed 's/sed //' < oldscript >sed_file

And then invoke as suggested by Shell_Life previously.

1 Like

Cheers guys that worked a treat :slight_smile: