Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Bash, Sed & Awk tutorials

  1. #1
    Join Date
    Jan 2009
    Location
    Denmark
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    Bash, Sed & Awk tutorials

    Hi all.

    Anyone know some really good / professional / usefull bash, awk and sed tutorials. That are up to date. I have worked with the 3 "languages" or w/e they are, on and off. But would like to get more in debt with it.

    And if anyone know of some good online tutorials, books, nuggets, others. That i'm all ears.

    Thanks on advance.
    Kind regards.

  2. #2
    Join Date
    Mar 2007
    Location
    Portsmouth, UK
    Beans
    Hidden!
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Re: Bash, Sed & Awk tutorials

    I've always found this resource to be very handy:

  3. #3
    Join Date
    Nov 2008
    Location
    Boston MetroWest
    Beans
    16,326

    Re: Bash, Sed & Awk tutorials

    For sed and awk, this is the Bible.

  4. #4
    Join Date
    Mar 2010
    Location
    /home
    Beans
    9,397
    Distro
    Xubuntu

    Re: Bash, Sed & Awk tutorials

    Quote Originally Posted by Grenage View Post
    I've always found this resource to be very handy:
    Excellent link Grenage; thanks

  5. #5
    Join Date
    Jan 2008
    Location
    Manchester UK
    Beans
    13,573
    Distro
    Ubuntu

    Re: Bash, Sed & Awk tutorials

    For bash

    http://mywiki.wooledge.org/BashGuide

    Check the faq and pitfalls section as well.

  6. #6
    Join Date
    Sep 2006
    Beans
    2,914

    Re: Bash, Sed & Awk tutorials

    You only need to learn awk out of sed/awk. Forget about sed. With awk, you can do what sed does , and much more, because Awk is a programming language itself. If you want to get more in depth on awk, look at its manual. (see my sig)

  7. #7
    Join Date
    Jan 2005
    Beans
    346

    Re: Bash, Sed & Awk tutorials

    ^ i'll agree with that in a genral sense, awk is more powerful and can do everything sed can. But for a lot of smaller things, sed is far quicker. my personal favorite is

    find /dir/ -iname "fileToSub*.txt" -exec sed -i -e 's/replace/new/g' {} \+

    try to do that with awk.

    OP, "advanced bash scripting guide" is good

    set -x
    set -e

  8. #8
    Join Date
    Sep 2006
    Beans
    2,914

    Re: Bash, Sed & Awk tutorials

    Quote Originally Posted by jerome bettis View Post
    ^ i'll agree with that in a genral sense, awk is more powerful and can do everything sed can. But for a lot of smaller things, sed is far quicker. my personal favorite is

    find /dir/ -iname "fileToSub*.txt" -exec sed -i -e 's/replace/new/g' {} \+

    try to do that with awk.
    don't forget, -exec is an option for the find command
    Code:
    find . -type f -name "file" -exec awk '{gsub(/replace/,"new")}1' "{}" > temp \; -exec mv temp "{}" \;
    true, awk doesn't have in place file editing feature, but i just showed you it can be done with just awk as well... and don't forget, sed -i also creates temp files in the back end.

  9. #9
    Join Date
    Feb 2007
    Beans
    4,045
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Bash, Sed & Awk tutorials

    Quote Originally Posted by ghostdog74 View Post
    Code:
    find . -type f -name "file" -exec awk '{gsub(/replace/,"new")}1' "{}" > temp \; -exec mv temp "{}" \;
    That will only work if there's at most one matching file. It's equivalent to
    Code:
    find . -type f -name "file" -exec awk '{gsub(/replace/,"new")}1' "{}" \; -exec mv temp "{}" \; > temp
    This'll edit the files using awk.
    Code:
    find . -type f -name "file" -exec awk '{gsub(/replace/,"new"); print > FILENAME}' {} +
    Oh and to the OP, for learning bash, stay away from the bash guides at tldp.org. Read the bash guide that nothingspecial posted. It's the only one that teaches good practice.
    Last edited by geirha; April 9th, 2011 at 01:14 PM.

  10. #10
    Join Date
    Jan 2005
    Beans
    346

    Re: Bash, Sed & Awk tutorials

    Quote Originally Posted by ghostdog74 View Post
    don't forget, -exec is an option for the find command
    Code:
    find . -type f -name "file" -exec awk '{gsub(/replace/,"new")}1' "{}" > temp \; -exec mv temp "{}" \;
    true, awk doesn't have in place file editing feature, but i just showed you it can be done with just awk as well... and don't forget, sed -i also creates temp files in the back end.
    i know it can be done, but look how much more work that was. thanks for helping me prove my point so well

    bash/sed/awk are all worth learning. i've been meaning to look at some other shells one of these days zsh/ksh/csh .. ive seen some people doing even more powerful stuff over there. But i'm so used to bash it is a bit weird.

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •