LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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, 03:21 PM   #1
kushalkoolwal
Senior Member
 
Registered: Feb 2004
Location: Middle of nowhere
Distribution: Debian Squeeze
Posts: 1,249

Rep: Reputation: 49
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, 03:31 PM   #2
jan61
Member
 
Registered: Jun 2008
Posts: 235

Rep: Reputation: 47
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, 03: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, 05:58 PM   #4
kushalkoolwal
Senior Member
 
Registered: Feb 2004
Location: Middle of nowhere
Distribution: Debian Squeeze
Posts: 1,249

Original Poster
Rep: Reputation: 49
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



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 12:52 AM
How to run multiple process in single command prompt babu198649 Linux - Newbie 7 10-12-2007 08:27 AM
Combining multiple directoreis into one Hegemon Linux - General 7 02-24-2007 11:37 AM
using multiple -exec commands in a single find command? Bluemilk Linux - Newbie 4 03-19-2006 10:46 AM
Compiling multiple .c file using single command in makefile vipulc Linux - General 2 03-18-2006 11:49 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:28 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration