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 ...
- 04-05-2007 #1
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.
- 04-05-2007 #2Just Joined!
- Join Date
- Jan 2007
- Posts
- 90
cat <> | awk -F'\$\$\$' '{print $1}'
- 04-06-2007 #3
Nopes, it didn't work. Tried it both using " " and ' '
Can anybody help us in this????
A
- 04-06-2007 #4Linux Engineer
- 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?
2) What part of a line are you considering the "first column"? ... cheers, drl
Originally Posted by Sangal-Arun
( 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 )
- 04-06-2007 #5
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
Originally Posted by drl
- 04-06-2007 #6Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi, Sangal-Arun.
Here is one solution:
Which produces: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
cheers, drlCode:% ./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
( 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 )
- 04-06-2007 #7Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
Try:
Dont cat the file to awk because the shell expands the $$$ characters to something unexpectable.Code:awk -F '\$\$\$' '{ print $1 }' filename
Regards
- 04-06-2007 #8
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
Originally Posted by drl
- 04-06-2007 #9
No Franklin... It didn't work.
I used:
awk -F"[$]+" '{print $1}' filename
Thanks to Drl.
Arun Sangal
Originally Posted by Franklin52
- 04-06-2007 #10Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
On my box it works well.
Originally Posted by Sangal-Arun
Regards


Reply With Quote