sed & awk

Hi.
I'm going to learn scripting and i have the following topics on the list: sed, awk, shell scripting, perl.

My question is, whehter i should learn sed and awk? Aren't this tools outdated?
Although i see that GNU upgrade it's versions of these tools from time to time.

And, the next question. Would the "Sed & awk" book be useful for reading on the sed topic? It is 1997.

For awk i'm going to read Effective awk Programming by GNU.

The sed & awk book is excellent for both. They are useful and stable tools which do not evolve much any more, but are still useful to have around. If you mean to be able to read and understand Unix shell scripts written by others, they are a must. Advanced sed scripting might not be all that useful to know if you are going to be learning awk and Perl anyway, but the basics (substitution, regex matching, maybe simple loops) are used a lot to make up for missing features in the shell.

PS I guess you know both books are available on-line for free?

http://www.gnu.org/software/gawk/manual/

thanks for the links era...

Good qns be kukuruku...

My question is, whehter i should learn sed and awk? Aren't this tools outdated?
Although i see that GNU upgrade it's versions of these tools from time to time.

Can somebody ans for the above please...

  • nani

if you want to choose 1 between the 2 , then learn awk.

those tools where created a long time ago, they are old, not outdated !!
there still beeing updated.
they are used alot in linux system scripts
a huge part of the scripts around relay on those

so, is it worth it ? (and pardon the my french) hell yeah

their importance is more clear after you learn how many things they can do

how much in depth you learn depends on what you spect to accomplish

I would suggest both are important assuming that perl is not in the choice list, had perl been there in the list it would do everything :b:

I feel its quite easier with sed to regex, information extraction etc.

Just my 2 cents :slight_smile:

It depends on what you want to do with Unix/Linux but first off, try to master the system utilities: ls, cat, cmp, grep, etc. and learn to use an editor like vi(m). Then, master the shell, you can do a great deal of useful work with just the shell and the utilities.

Once you've learned how to write useful scripts in the shell, try to master utilities like sed and awk.
After that you can think about a program language and that depends on what you want to do.

Regards

Its even easier and code made more readable when regex is not used :slight_smile: (at least not that much). sed can be used for short little regex , anything more complex makes code not easy to understand.

Yes ... slowly. ;-))

I don't want to indulge into the perl-as-a-language-discussion. Suffice it to say that the discussion taking place is enough to make me wary about it. Being disputable is a sign of being problematic regardless of the dispute being carried out or not.

Regarding the thread openers question: sed and awk are tools for different purposes and the question which one to learn makes about as much sense as the question "should i learn the hammer or the nail tool". You will need both.

It is quite common to misuse one tool for a purpose where the other would be better suited. That doesn't make the practice any better - just more common.

To find out which tool to use for which purpose just look at their differences: sed is faster and smaller than awk. awk, on the other hand, is able to work context-sensitive and has a much bigger function library. As a rule of thumb: if you can do it in sed, than do it in sed, in any other case use awk. If you have a line-oriented file and you want to parse out some values from each line and create a nicely aligned table probably sed will be the right tool for you. If you want to sum on one of the fields and write the total in the last line your tool of choice is awk.

If the problem you are trying to solve involves lots of processing you might save a lot of time using sed instead of awk. If the problem is complex and interdependent you might be able to solve it with awk easily and straightforwardly but only with a lot of "programming magic" (if at all) with sed. Bottom line: use every tool for what it is designed to achieve. "One size fits all" is as bad a concept when it comes to chosing tools as it is with condome sizes.

I hope this helps.

bakunin

in some cases, using sed on large files tend to be slower than using awk.