Solved

What this sed do?

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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.…
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 …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

734 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