LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-16-2008, 04:21 PM   #1
kushalkoolwal
Senior Member
 
Registered: Feb 2004
Location: Middle of nowhere
Distribution: Debian Squeeze
Posts: 1,249

Rep: Reputation: 48
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
 
Old 09-16-2008, 04:31 PM   #2
jan61
Member
 
Registered: Jun 2008
Posts: 235

Rep: Reputation: 46
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
 
Old 09-16-2008, 04:33 PM   #3
AuroraCA
Member
 
Registered: Jul 2008
Location: Northern CA USA
Distribution: Ubuntu, Slackware, Gentoo, Fedora, Red Hat, Puppy Linux
Posts: 370

Rep: Reputation: 35
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.
 
Old 09-16-2008, 06:58 PM   #4
kushalkoolwal
Senior Member
 
Registered: Feb 2004
Location: Middle of nowhere
Distribution: Debian Squeeze
Posts: 1,249

Original Poster
Rep: Reputation: 48
Quote:
Originally Posted by jan61 View Post
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!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Combining the install & live CD into a single CD austinium Debian 4 07-06-2008 01:52 AM
How to run multiple process in single command prompt babu198649 Linux - Newbie 7 10-12-2007 09:27 AM
Combining multiple directoreis into one Hegemon Linux - General 7 02-24-2007 12:37 PM
using multiple -exec commands in a single find command? Bluemilk Linux - Newbie 4 03-19-2006 11:46 AM
Compiling multiple .c file using single command in makefile vipulc Linux - General 2 03-19-2006 12:49 AM


All times are GMT -5. The time now is 11:13 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration