Lots of sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Lots of sed
# 1  
Old 09-29-2011
Lots of sed

Hi,

I have 200 lines of sed commands in a shellscript

Code:
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
# 2  
Old 09-29-2011
Create a file with all your sed statements as:
Code:
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:
Code:
sed -f sed_file Input_File

This User Gave Thanks to Shell_Life For This Post:
# 3  
Old 09-29-2011
not sure your real purpose, if you only need replace _1 to _24, maybe just

Code:
s/_1/_24/g

or maybe try this command to replace all of them.

Code:
sed "s/\([^ ]*\)_1/\1_24/g" infile

# 4  
Old 09-30-2011
Code:
echo 123 | sed -n 's/1/2/g;s/2/3/gp'


Last edited by Scott; 09-30-2011 at 04:52 AM.. Reason: Code tags
# 5  
Old 10-03-2011
I have tried using this one

Code:
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
# 6  
Old 10-03-2011
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
Code:
sed 's/sed //' < oldscript >sed_file

And then invoke as suggested by Shell_Life previously.
This User Gave Thanks to hartz For This Post:
# 7  
Old 10-03-2011
Cheers guys that worked a treat Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to rename lots of files with find?

Can someone help me with this script. I have a bunch of files like this: "2209OS_02_Code" "2209OS_03_Code" "2209OS_04_Code" "2209OS_05_Code" "2209OS_06_Code" "2209OS_07_Code" "2209OS_08_Code" "2209OS_09_Code" "2209OS_10_Code" "2209OS_10_video" and I want to rename them to be like this: ... (2 Replies)
Discussion started by: siegfried
2 Replies

2. UNIX and Linux Applications

From past 10 days my one job is taking lots of time

One of my job is taking long running time. I need to identify from the unix log file can you please help how to troubleshoot. (1 Reply)
Discussion started by: Nsharma3006
1 Replies

3. IP Networking

netstat showing lots of errors

Hi, I have a server which receive lots of events to it and when I do netstat -Ie1000g0, I'm seeing the errors as below. Name Mtu Net/Dest Address Ipkts Ierrs Opkts Oerrs Collis Queue e1000g0 1500 abc-1.com abc-1.com 3093708246 12757 92069412 0 0 0 If anyone could direct me to right... (3 Replies)
Discussion started by: mohzub
3 Replies

4. AIX

Lots of page faults and free memory

Hello, I've been reading your forums for quite a while and the great amount of information I find here always come in hand.This time however, I need some specific help... I have a doubt with an AIX server which I'm failing to understand as I'm new to its concept of memory management... ... (8 Replies)
Discussion started by: flpgdt
8 Replies

5. Programming

problem with lots of open sockets

I'm programming in C with lots of sockets, (asynchronous handling), and for a while it goes ok, but after a while it starts to hang, or not get complete connections anymore. checking my router, i see that i get nat tables overflow and even my DNS cacher seems to be having serious issues... ... (4 Replies)
Discussion started by: alien999999999
4 Replies

6. Red Hat

Lots of questions about linux.

I am about 2 months new to Linux, and have only limited experience with PCLinuxOS, (kde) and Redhat. I am installing the latest version of PClinuxOS on my wife's PC right now but running into a problem I dont understand. I have never seen it before so i thought i'd ask how I can get around it.... (1 Reply)
Discussion started by: Methal
1 Replies

7. UNIX for Dummies Questions & Answers

Deleting lots of files.....

Hi All, Thanks in advance for reading and any posts... I have to delete a lot of files (about 6 pages of a4 (ls -ltr)) but I have to keep some as well. I would normally do an rm * to get rid of them all, but thats not what I want to do. Is there anyway I could rm * but add in a list of... (8 Replies)
Discussion started by: B14speedfreak
8 Replies

8. UNIX for Dummies Questions & Answers

Lots of file copyingand renaming?

I have Approx 1000 files that all need to be copied from one directory to another. However, each file has to be renamed while it is copied. I have a Tab delimited text file containing all of the old and new file names (they are not all the same character length). Is there a way to read in the... (12 Replies)
Discussion started by: AeroEngy
12 Replies
Login or Register to Ask a Question