Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

What this sed do?

Posted on 2008-06-11
3
Medium Priority
?
257 Views
Last Modified: 2010-04-16
sed -e '1d' result.txt        eliminates the first line from file result.txt  -------------> is this 1d is first line?

sed -n '/stringa1/p'       view only lines that contain the word "string1" ---------> what is -n ? what is '/' ? what is p ?

sed -e 's/ *$//' example.txt       remove empty characters at the end of each row -------> what is -e ? what is  *$ ... why a slash in between ? what does // mean?
0
Comment
Question by:jaisonshereen
  • 2
3 Comments
 
LVL 85

Accepted Solution

by:
ozo earned 1200 total points
ID: 21763146
1 is the first line, d is delete
 
     -n      By default, each line of input is echoed to the standard output
             after all of the commands have been applied to it.  The -n option
             suppresses this behavior.


     -e command
             Append the editing commands specified by the command argument to
             the list of commands.

* in this context means 0 or more of the preceeding character $ is the end of the line,
the character after the s delimits the pattern and replacement

see
man sed
0
 
LVL 85

Expert Comment

by:ozo
ID: 21763173
/stringa1/ addresses lines matching the pattern,  p prints
0
 
LVL 7

Assisted Solution

by:rugdog
rugdog earned 800 total points
ID: 21772598
sed -e 's/ *$//' example.txt

has a slash in between, meaning the replacement string is the empty string. To understand it in a different way, if you wanted to replace the spaces at the end with an x you would:

sed -e 's/ *$/x/' example.txt

but you want to remove them or replace them with nothing, hence //.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show, step by step, how to integrate R code into a R Sweave document
Utilizing an array to gracefully append to a list of EmailAddresses
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Six Sigma Control Plans
Suggested Courses

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question