Solved

What this sed do?

Posted on 2008-06-11
3
246 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 84

Accepted Solution

by:
ozo earned 300 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 84

Expert Comment

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

Assisted Solution

by:rugdog
rugdog earned 200 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
The viewer will learn how to count occurrences of each item in an array.
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…

726 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