LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   combining multiple sed operations into a single command (https://www.linuxquestions.org/questions/programming-9/combining-multiple-sed-operations-into-a-single-command-670331/)

kushalkoolwal 09-16-2008 03:21 PM

combining multiple sed operations into a single command
 
Hi,

I would like to combine the following four "sed" commands into a single command so that the "sed" does not have to go through the entire text file (around 1 GB) four times.

Code:

sed "/latency/d" $INFILE > tmp;
mv tmp $TEMPFILE

sed  "/usecs/d" $TEMPFILE > tmp;
mv tmp $TEMPFILE

sed  "/exiting/d" $TEMPFILE > tmp;
mv tmp $TEMPFILE

sed  "/total/d" $TEMPFILE > tmp;
mv tmp $TEMPFILE

Thanks

jan61 09-16-2008 03:31 PM

Moin,

you can separate different sed commands using the semicolon:
Code:

sed '/latency/d;/usecs/d;/exiting/d;/total/d' $INFILE
another way:
Code:

sed -r '/(latency|usecs|exiting|total)/d' $INFILE
Jan

AuroraCA 09-16-2008 03:33 PM

This could be done in one of two ways.

You could use the | or tee command to pipe the output of one sed command to the next. Alternatively, you could set up a named pipe to input the output of one command to the next.

kushalkoolwal 09-16-2008 05:58 PM

Quote:

Originally Posted by jan61 (Post 3282370)
Moin,

you can separate different sed commands using the semicolon:
Code:

sed '/latency/d;/usecs/d;/exiting/d;/total/d' $INFILE
another way:
Code:

sed -r '/(latency|usecs|exiting|total)/d' $INFILE
Jan

Thank you. That worked!


All times are GMT -5. The time now is 05:14 AM.