?
Solved

What this sed do?

Posted on 2008-06-11
3
Medium Priority
?
255 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 84

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 84

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

How To Reduce Deployment Times With Pre-Baked AMIs

Even if we can't include all the files in the base image, we can sometimes include some of the larger files that we would otherwise have to download, and we can also sometimes remove the most time-consuming steps. This can help a lot with reducing deployment times.

Question has a verified solution.

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

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Suggested Courses

719 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