LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-11-2010, 02:14 PM   #1
coolloo_djack
LQ Newbie
 
Registered: Feb 2010
Location: abidjan - côte d'ivoire
Distribution: redhat, debian, solaris
Posts: 7

Rep: Reputation: 0
Question working on bash: wante to no what a combinasion of commands(grep, sed) do ?


hello!

I'm learning "grep" and "sed" command; So I don't no exactly what the command line below, does :

command line: grep Shell /usr/share/doc/ | sed '/README\./d' | grep README | wc -l

thank you for answering
 
Old 03-11-2010, 03:15 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by coolloo_djack View Post
hello!

I'm learning "grep" and "sed" command; So I don't no exactly what the command line below, does :

command line: grep Shell /usr/share/doc/ | sed '/README\./d' | grep README | wc -l

thank you for answering
Your other thread about grep should tell you what grep does. Sed is a stream editor. Type in "man grep" and "man sed" for explanations as to what the commands do.

So read out the line: You're looking for the word Shell in /usr/share/doc, then sending it through sed, where it deletes all lines that contain an upper-case "README." Then it pipes it into grep for README, then to word count.

As it stands there, it makes no sense, since all the lines with README are getting deleted before they're counted.
 
1 members found this post helpful.
Old 03-11-2010, 08:44 PM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by TB0ne View Post
As it stands there, it makes no sense, since all the lines with README are getting deleted before they're counted.
I'm no sed-spert but wonder if that is true; is it not only the lines with 'README.' that are deleted? The pipeline seems designed to count the number of occurrences of README that are not at the end of a sentence. Could turn out to be very popular, like sliced bread or hot cakes

Two sed links:
http://www.grymoire.com/Unix/Sed.html
http://sed.sourceforge.net/sedfaq.html

Last edited by catkin; 03-11-2010 at 08:46 PM. Reason: Whimsy
 
Old 03-11-2010, 10:29 PM   #4
primerib
Member
 
Registered: Mar 2010
Posts: 48

Rep: Reputation: 20
Quote:
Originally Posted by coolloo_djack View Post
hello!

I'm learning "grep" and "sed" command; So I don't no exactly what the command line below, does :

command line: grep Shell /usr/share/doc/ | sed '/README\./d' | grep README | wc -l

thank you for answering
grep Shell /usr/share/doc/ | sed '/README\./d' | grep README | wc -l
The bold part searches for "Shell" in /usr/share/doc/. However, /usr/share/doc/ specifies a directory, not a file, therefore grep will not return any result. You should do grep Shell /usr/share/doc/some_file (assuming you're trying to search within a file).

grep Shell /usr/share/doc/ | sed '/README\./d' | grep README | wc -l
Pretending your first grep worked and returned "README.", the bold part, | sed '/README\./d', searches for "README." in the grep return and deletes it. For example:

$ echo -e "README.\nREADME\nREADME."
README.
README
README.
$ echo -e "README.\nREADME\nREADME." | sed '/README\./d'
README
$

grep Shell /usr/share/doc/ | sed '/README\./d' | grep README | wc -l
The bold part searches the result AFTER the first grep and sed commands for "README". Of which there is one in the result.

$ echo -e "README.\nREADME\nREADME."
README.
README
README.
$ echo -e "README.\nREADME\nREADME." | sed '/README\./d' | grep README
README
$

grep Shell /usr/share/doc/ | sed '/README\./d' | grep README | wc -l
The bold part then counts how many lines there are in after the first grep, sed, and second grep. The result would be one.

$ echo -e "README.\nREADME\nREADME." | sed '/README\./d' | grep README | wc -l
1
$
 
1 members found this post helpful.
Old 03-12-2010, 03:24 AM   #5
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by coolloo_djack View Post
hello!

I'm learning "grep" and "sed" command; So I don't no exactly what the command line below, does :

command line: grep Shell /usr/share/doc/ | sed '/README\./d' | grep README | wc -l

thank you for answering
the above can be done with just one awk command.

Code:
awk '/Shell/ &&!/README\./ &&/README/{++c}END{print c}' /usr/share/doc
therefore, learn awk instead
 
1 members found this post helpful.
  


Reply

Tags
bash



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[Bash] - sed - read commands from file mrq Programming 4 08-24-2009 06:43 AM
bash - awk, sed, grep, ... advice schneidz Programming 13 08-25-2008 09:30 AM
I am learning sed / grep working and am stuck with a problem chris_looks Linux - Newbie 12 08-14-2007 11:13 AM
I am learning sed / grep working and am stuck with a problem chris_looks Linux User Groups (LUG) 2 08-06-2007 01:31 PM
bash script with grep and sed: sed getting filenames from grep odysseus.lost Programming 1 07-17-2006 11:36 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:01 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration