Operating System - HP-UX
1751786 Members
4988 Online
108781 Solutions
New Discussion юеВ

Which came first, the sed & awk or the Perl?

 
SOLVED
Go to solution
Jim Mallett
Honored Contributor

Which came first, the sed & awk or the Perl?

Ok, I've picked up a few scripting books recommended on the forum and I'm going to dive into them this weekend. Which would be the logical first choice to read? Sed & Awk, or Perl? Does one lend itself to the other? How much coffee should I make beforehand?

Actually, one other question. I have Cygwin on my laptop and can practice scripting at home. Will I find the Cygwin versions of sed/awk/perl to be different than the HP-UX releases? (extra pts for this one)

Any thoughts are appreciated....

Jim Mallett
Hindsight is 20/20
17 REPLIES 17
Chris Vail
Honored Contributor

Re: Which came first, the sed & awk or the Perl?

Study BOTH, or ALL (depending on how you phrase it)

I've been doing shell scripting in one form or fashion for nearly 20 years, and I'm still learning stuff. Open in front of me on the desk I type this are 3 O'Reilly books: _Learning Perl_, _Effective Awk Programming_, and _Mastering Regular Expresssions_.

These are all complementary, not competing. They work together quite well. I really know nothing of PERL, but am learning. Sed & awk are what I use most commonly, but awk is a programming language all by itself. Generally, PERL is considered a superset of awk.

Most importantly: LOTS of coffee, followed by beer.

Chris
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Which came first, the sed & awk or the Perl?


Both are good BUT if I were starting over, I would go only with Perl. There is really nothing you can do with sed, awk, sort, grep, sh, ... that you can't do with Perl directly. The price you pay is that the learning curve is steeper but the regular expressions in Perl are on steroids. If you learn Perl RE's first then some of the things can't be applied to sed or awk.

About the only thing I turn to awk first for is simple one-liners that print maybe the 3rd and 5th field of each line. Awk is a little simpler for tasks like that but Perl is really the weapon of choice these days.

In a very real sense, the only need for awk/sed knowledge is to fix/maintain legacy code. All of my new scripting is Perl and as a bonus if carefully written will run platform independently -- and not just UNIX.

Your Cygwin versions will be close enough. There will be minor awk differences and basically Perl 5.6 is Perl 5.6 but Perl will have modules that are OS/Platform specific but those are not the typical day-to-day Perl tasks.


If it ain't broke, I can fix that.
Tim D Fulford
Honored Contributor

Re: Which came first, the sed & awk or the Perl?

I would go for perl, it is more powerful than sed or awk.

If you master perl, then sed & awk will be that much easier.

regards

Tim
-
John Bolene
Honored Contributor

Re: Which came first, the sed & awk or the Perl?

Perl is a whole programming language by itself and by far the most powerful of what you mentioned and it is extendable thru the addition of other modules.

Sed and awk were made shortly after UNIX was invented.

If you learn Perl, you may not need anything else.
It is always a good day when you are launching rockets! http://tripolioklahoma.org, Mostly Missiles http://mostlymissiles.com
Caesar_3
Esteemed Contributor

Re: Which came first, the sed & awk or the Perl?

Hello!

If you want to be good in system then
you should learn every thing!
Perl is the best, you can do with what ever
you want.

Sed&Awk give you the power in the command line.

About the coffee so if you know programing
(line C, pascal, etc.) then it would be hard
so not to much coffee if not then you will need
more coffee.

I know that perl in hpux (unix kind) a little
diffrent than in win systems, more function
you have on unix, but for basic programming
you would see a diffrent.

Search on the net for book by O'really
you will find good books about perl, sed & awk

Caesar
Shannon Petry
Honored Contributor

Re: Which came first, the sed & awk or the Perl?

Well, the title of your question is answered much differently than your question. First was ed, then sed, then awk, then perl.

Now that that's overwith, here is what you need to master before handling any of the 3. Regular expressions!

sed, awk, and perl all use the same exact regular expressions. If you can master in 1, you can master in all. Since sed is the fastest way to test your regular expressions, get the knack for them here.

Now for programming, if I went back in time I would have dont alot more of my work in Perl. Sadly, perl is not available for at the same level for all Unices, and I work on many. IMHO it would have been worth it to compile it for each and use it.

As for practicing on your laptop with cygwin, the sed, awk and perl work the same. However remember that the base OS is still windblows, so critical things you could do in Unix just can not possibly exist.

Regards,
Shannon
Microsoft. When do you want a virus today?
Michael Steele_2
Honored Contributor

Re: Which came first, the sed & awk or the Perl?

Perl.

Perl.

Study alot of Perl.

You can market Perl on your resume. SED and AWK are mostly obsolete.

Here's what you need to know about awk:

cat file | awk '{ print $0 $1 $2 $3 }'

That's it!

Here what you need to know about sed:

VAR=$(echo $PATH | sed -e -s "/\// /g" )

That's it!

Everything else can be done faster and more efficiently in perl. And if you want to learn then copy and apply everything from this thread:

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x026250011d20d6118ff40090279cd0f9,00.html

Those books might be good for reference but don't read them cover to cover.

Also, get a 4mm tape and start tar'ing all of your scripts onto tape so you always have them.
Support Fatherhood - Stop Family Law
Leif Halvarsson_2
Honored Contributor

Re: Which came first, the sed & awk or the Perl?

Hi,
There may be one important reason why also learn something about awk and sed. You will find awk and sed on all Unix boxes but perhaps not Perl (and you are perhaps not allowed to install it everywhere). The same reason why it is important to know something about vi, it is always avialable.
William Wong_2
Trusted Contributor

Re: Which came first, the sed & awk or the Perl?

For the first part of the question: sed was first as it was written by Lee E. McMahon in 1973 or 1974, awk was next and was written in 1977. The name awk comes from the initials of its designers: Alfred V. Aho, Peter J. Weinberger, and Brian W. Kernighan and perl was last as it was first released in 1987 by Larry Wall.

As previously stated it doesn't hurt to learn all of them. Yes they do lend to each other in
some regards such as their support of regular expressions.

For the final piece of the question there are some minor differences in the behavior and how it processes certain types of information between the Cygwin versions of sed and awk and the HP-UX versions. Perl should be the same for both.