Solved

What this sed do?

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now