LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
Email to...
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG] new grep

[ILUG] new grep

Padraig Brady padraig at antefacto.com
Mon Mar 25 17:45:34 GMT 2002


kevin lyda wrote:
> On Mon, Mar 25, 2002 at 05:05:39PM +0000, Padraig Brady wrote:
> 
>>Why?
>>
>>sed -n -e "/[0-9]/p" testfile
>>
>>is the same as:
>>
>>grep "[0-9]" testfile
> 
> 
> no it's not if the file args are testfile1 and testfile2.  and that's a
> good thing because if i'm editing files i don't want prefixes on the lines
> i'm playing with.

Again sed could easily default to printing filename prefixes if more
than one file specified.

>  however for your example, they're both the same as:
> 
>   awk '/[0-9]/{print}' testfile
> 
> or
> 
>   perl -ne '/[0-9]/ && print' testfile

true

> or
> 
>   while read l; do case "$l"; in *[0-9]*) echo "$l" ;; esac; done < testfile

don't be silly

> so should we roll the functionality of awk, perl and shell into sed?

err (don't be silly)^2, they're general purpose languages

> and you ignored my comment about complexity.  to do a simple search you
> required two flags, two slashes and a p command.  that's insane.

But one less command to know about.

> plus i don't see any docs concerning sed's return codes and what they
> mean - rather important in scripts that use grep.

again easy to change if they're not appropriate.

At this stage grep is obviously not going away,
but perhaps as a first stage you could merge sed/grep
to 1 binary, that behaves a little differently
depending on what argv[0] is, and also make
any (tiny) changes to sed to provide all of grep's
functionality.

> 
>>With a common function of finding a pattern.
> 
> 
> sometimes.  you can also have sed add a boilerplate license at the top
> of each license file.  no searching, just position.  otoh, sometimes
> you just want grep to say the pattern exists, not to print it:
> 
>     if grep -l foo bar > /dev/null 2>&1; then
> 	echo get a beer for foo
>     else
> 	echo sing mournfully for foo
>     fi
> 
> 
>>I think it's as easy for someone to learn the p command
>>in sed, as a seperate grep command. That just takes a
>>minute or two. The hard bit is understanding the regular
>>expressions.
> 
> 
> personally, i like anything that reduces typing.
> 

personally I like nice narrow/general interfaces, which
is one of the things that makes UNIX so much nicer to
program than doze.

Padraig.





More information about the ILUG mailing list
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


Maintained by the ILUG website team. The aim of Linux.ie is to support and help commercial and private users of Linux in Ireland. You can display ILUG news in your own webpages, read backend information to find out how. Networking services kindly provided by HEAnet, server kindly donated by Dell. Linux is a trademark of Linus Torvalds, used with permission. No penguins were harmed in the production or maintenance of this highly praised website. Looking for the Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!
RSS Version
Powered by Dell