Thread: Using awk !!!

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    45
    Rep Power
    12

    Using awk !!!


    Hello I have a line like this
    Product Name: eserver xSeries 336 -[abcdefgh]-
    I'd like to get the string abcdefgh in shell using sed, awk or whatever else fits
    I tryed awk /\[/,/\]/p but it doesn't work. I tryed many things but awk or sed without any success.

    Any advice on how to do it ?
  2. #2
  3. fork while true;
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    May 2005
    Location
    England, UK
    Posts
    5,538
    Rep Power
    1051
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    45
    Rep Power
    12
    Thanx, penguin but I'd like to know how to do it in shell.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    London, England
    Posts
    1,585
    Rep Power
    1373
    You can use sed to strip off everything up to and including the '[', and everything from the ']' to the end of line:

    Code:
    $ echo 'eserver xSeries 335 -[abcdefgh]-' | sed 's/.*\[//;s/\].*//'
    abcdefgh
    I think using ';' to separate two sed commands is undocumented - to be on the safe side you could put them on separate lines:

    Code:
    $ echo 'eserver xSeries 335 -[abcdefgh]-' | sed 's/.*\[//
    s/\].*//'
    abcdefgh
    Dave
  8. #5
  9. fork while true;
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    May 2005
    Location
    England, UK
    Posts
    5,538
    Rep Power
    1051
    Originally Posted by DevCoach
    You can use sed to strip off everything up to and including the '[', and everything from the ']' to the end of line:

    Code:
    $ echo 'eserver xSeries 335 -[abcdefgh]-' | sed 's/.*\[//;s/\].*//'
    abcdefgh
    I think using ';' to separate two sed commands is undocumented - to be on the safe side you could put them on separate lines:

    Code:
    $ echo 'eserver xSeries 335 -[abcdefgh]-' | sed 's/.*\[//
    s/\].*//'
    abcdefgh
    Dave
    You could also use two -e statements You can build up a multiline script like that
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    45
    Rep Power
    12
    Thanx you very much for this solution

IMN logo majestic logo threadwatch logo seochat tools logo