Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 17
Suppose I have the following lines in a file: /vob/efs/class.tcl@@/main/pub-int/arne-dev/1$$$c098302$$$Allow to routes. /vob/efs/abc.pl@@/main/pub-int/arne-dev/1$$$qabuild$$$Rebase done /vob/efs/travel.pl@@/main/pub-int/arne-dev/10$$$e027485$$$FSN3972 /vob/efs/travel.pl@@/main/pub-int/arne-dev/3$$$qabuild$$$Rebase /vob/efs/baggage.pl@@/main/pub-int/arne-dev/19$$$qabuild$$$Rebase done Now, how can get the 1st column with using "awk" (Note: Using ...
  1. #1
    Linux Newbie Sangal-Arun's Avatar
    Join Date
    May 2006
    Location
    Gurgaon, India + Denver Colorado USA
    Posts
    101

    Red face awk -F"$$$": Get column 1 with delimiter having multiple characters having "$" char

    Suppose I have the following lines in a file:

    /vob/efs/class.tcl@@/main/pub-int/arne-dev/1$$$c098302$$$Allow to routes.
    /vob/efs/abc.pl@@/main/pub-int/arne-dev/1$$$qabuild$$$Rebase done
    /vob/efs/travel.pl@@/main/pub-int/arne-dev/10$$$e027485$$$FSN3972
    /vob/efs/travel.pl@@/main/pub-int/arne-dev/3$$$qabuild$$$Rebase
    /vob/efs/baggage.pl@@/main/pub-int/arne-dev/19$$$qabuild$$$Rebase done

    Now, how can get the 1st column with using "awk" (Note: Using awk only....) if I assume to delimit it by using "$$$" characters. i.e. multiple $ character should be treated as 1 delimiter in a line.

    Kindly help.
    Brgds,

    ARUN SANGAL
    SCM: 1- 720 251 9962
    Email: sangal.ak04@gmail.com
    Email: sangal_ak04@yahoo.com

  2. #2
    Just Joined!
    Join Date
    Jan 2007
    Posts
    90
    cat <> | awk -F'\$\$\$' '{print $1}'

  3. #3
    Linux Newbie Sangal-Arun's Avatar
    Join Date
    May 2006
    Location
    Gurgaon, India + Denver Colorado USA
    Posts
    101
    Nopes, it didn't work. Tried it both using " " and ' '

    Can anybody help us in this????

    A
    Brgds,

    ARUN SANGAL
    SCM: 1- 720 251 9962
    Email: sangal.ak04@gmail.com
    Email: sangal_ak04@yahoo.com

  4. #4
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
    Posts
    1,117
    Hi.
    1) Restricting the solution set to awk may cause better solutions to be lost, ignored, etc. Why are you doing that?
    Quote Originally Posted by Sangal-Arun
    ... (Note: Using awk only....) ...
    2) What part of a line are you considering the "first column"? ... cheers, drl

    ( edit 1: typo )
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  5. #5
    Linux Newbie Sangal-Arun's Avatar
    Join Date
    May 2006
    Location
    Gurgaon, India + Denver Colorado USA
    Posts
    101
    Hi Drl,

    Hope you are doing fine..

    Actually the file I'm going to change uses awk very much in its coding...mostly. That's why I asked to get the 1st column with using awk...

    Yups.. I want only the 1st part....and that can be picked up using various methods...but I'm restricted to change the whole script.

    If required, I will try change the script as a whole.


    Any helps!

    Arun Sangal



    Quote Originally Posted by drl
    Hi.
    1) Restricting the solution set to awk may cause better solutions to be lost, ignored, etc. Why are you doing that?

    2) What part of a line are you considering the "first column"? ... cheers, drl

    ( edit 1: typo )
    Brgds,

    ARUN SANGAL
    SCM: 1- 720 251 9962
    Email: sangal.ak04@gmail.com
    Email: sangal_ak04@yahoo.com

  6. #6
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
    Posts
    1,117
    Hi, Sangal-Arun.

    Here is one solution:
    Code:
    #!/bin/sh
    
    # @(*) s5       Demonstrate awk field splitting with regular expression.
    
    FILE=${1-data1}
    
    gawk '
    BEGIN   { FS = "[$]+"; print " Field separator is ", FS }
            { print "NF =",NF,"field 1 =",$1 }
    ' $FILE
    Which produces:
    Code:
    % ./s5
     Field separator is  [$]+
    NF = 3 field 1 = /vob/efs/class.tcl@@/main/pub-int/arne-dev/1
    NF = 3 field 1 = /vob/efs/abc.pl@@/main/pub-int/arne-dev/1
    NF = 3 field 1 = /vob/efs/travel.pl@@/main/pub-int/arne-dev/10
    NF = 3 field 1 = /vob/efs/travel.pl@@/main/pub-int/arne-dev/3
    NF = 3 field 1 = /vob/efs/baggage.pl@@/main/pub-int/arne-dev/19
    cheers, drl

    ( edit 1: typo )
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  7. #7
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    Try:

    Code:
    awk -F '\$\$\$' '{ print $1 }' filename
    Dont cat the file to awk because the shell expands the $$$ characters to something unexpectable.

    Regards

  8. #8
    Linux Newbie Sangal-Arun's Avatar
    Join Date
    May 2006
    Location
    Gurgaon, India + Denver Colorado USA
    Posts
    101

    Thumbs up

    You are GREAT.

    I used the same funda with awk and it worked.. Thanks for your help.

    [/E*Fare/Users/qabuild/aksutil/P/pawan] $ head -2 arne; echo -e "\n\n" ; head -2 arne|awk -F"[$]+" '{print $1}'
    /vob/efs/EFare/meta-inf/AFarepf3Form.class.tcl@@/main/pub-int/arne-dev/1$$$c098302$$$Allow for follow to routes.
    /vob/efs/EFare/Server/acctravel.pl@@/main/pub-int/arne-dev/1$$$qabuild$$$Rebase done from to arne by Pankaj Agarwal -- on Mon Feb 5 16:12:54 GMT 2007



    /vob/efs/EFare/meta-inf/AFarepf3Form.class.tcl@@/main/pub-int/arne-dev/1
    /vob/efs/EFare/Server/acctravel.pl@@/main/pub-int/arne-dev/1


    Brgds,
    Arun Sangal


    Quote Originally Posted by drl
    Hi, Sangal-Arun.

    Here is one solution:
    Code:
    #!/bin/sh
    
    # @(*) s5       Demonstrate awk field splitting with regular expression.
    
    FILE=${1-data1}
    
    gawk '
    BEGIN   { FS = "[$]+"; print " Field separator is ", FS }
            { print "NF =",NF,"field 1 =",$1 }
    ' $FILE
    Which produces:
    Code:
    % ./s5
     Field separator is  [$]+
    NF = 3 field 1 = /vob/efs/class.tcl@@/main/pub-int/arne-dev/1
    NF = 3 field 1 = /vob/efs/abc.pl@@/main/pub-int/arne-dev/1
    NF = 3 field 1 = /vob/efs/travel.pl@@/main/pub-int/arne-dev/10
    NF = 3 field 1 = /vob/efs/travel.pl@@/main/pub-int/arne-dev/3
    NF = 3 field 1 = /vob/efs/baggage.pl@@/main/pub-int/arne-dev/19
    cheers, drl

    ( edit 1: typo )
    Brgds,

    ARUN SANGAL
    SCM: 1- 720 251 9962
    Email: sangal.ak04@gmail.com
    Email: sangal_ak04@yahoo.com

  9. #9
    Linux Newbie Sangal-Arun's Avatar
    Join Date
    May 2006
    Location
    Gurgaon, India + Denver Colorado USA
    Posts
    101

    Thumbs up

    No Franklin... It didn't work.

    I used:

    awk -F"[$]+" '{print $1}' filename

    Thanks to Drl.
    Arun Sangal


    Quote Originally Posted by Franklin52
    Try:

    Code:
    awk -F '\$\$\$' '{ print $1 }' filename
    Dont cat the file to awk because the shell expands the $$$ characters to something unexpectable.

    Regards
    Brgds,

    ARUN SANGAL
    SCM: 1- 720 251 9962
    Email: sangal.ak04@gmail.com
    Email: sangal_ak04@yahoo.com

  10. #10
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    Quote Originally Posted by Sangal-Arun
    No Franklin... It didn't work.
    On my box it works well.

    Regards

Page 1 of 2 1 2 LastLast

Posting Permissions

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