AWK double delimiter


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK double delimiter
# 1  
Old 09-17-2010
AWK double delimiter

Hello,
an awk style question (or a stupid question... it depends on your point of view Smilie )
How can I write in one awk command these two ones ?

Code:
$USER - `grep $USER /etc/passwd | awk -F: '{ print $5 }' | awk -F, '{  print $1 }'`

Thanks
gb
# 2  
Old 09-17-2010
In the awk -F option you can use a regular expression.
Check below:
Code:
# echo "a:b,c" | awk -F"[,|:]" '{print $1 " " $2 " " $3}'
a b c

# 3  
Old 09-17-2010
Gracias Felipe for you answer,
but I'm not looking at this.
I want a sequentially awk search :
first with delimiter ":"
after with delimiter ","

br
# 4  
Old 09-17-2010
Not sure of what you want try :

Code:
$USER - $(grep $USER /etc/passwd | awk -F: '{gsub(",","",$5); print $5}')

or

Code:
$USER - $(grep $USER /etc/passwd | awk -F: '{split($5,a,","); print a[1]}')

# 5  
Old 09-17-2010
Code:
awk -F: '$0 ~ user { 
  print substr($5, 1, index($5, ",") - 1)
  }' user="$USER" /etc/passwd

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract multiple columns base on double quotes as delimiter

Hi All, I have my data like below "1","abc,db","hac,aron","4","5" Now I need to extract 1,2,4th columns Output should be like "1",abc,db","4" Am trying to use cut command but not able to get the results. Thanks in advance. (4 Replies)
Discussion started by: weknowd
4 Replies

2. Shell Programming and Scripting

Skip the delimiter with in double quotes and count the number of delimiters during data extract

Hi All, I'm stuck-up in finding a way to skip the delimiter which come within double quotes using awk or any other better option. can someone please help me out. Below are the details: Delimited: | Sample data: 742433154|"SYN|THESIS MED CHEM PTY.... (2 Replies)
Discussion started by: BrahmaNaiduA
2 Replies

3. Shell Programming and Scripting

Need to use delimiter as : and space in awk

Hi , Please suggest me how do I use : (colon and one space) as a delimiter in awk Best regards, Vishal (2 Replies)
Discussion started by: Vishal_dba
2 Replies

4. UNIX for Dummies Questions & Answers

Help with awk using * (asterisk) as the delimiter

Hi I am trying to parse the following lines and has to use * (asterisk) as the delimiter. These lines are in a file, for example tmp.txt and I am using a while loop tmp.txt: 14-OCT-2012 06:38:59 *... (1 Reply)
Discussion started by: newbie_01
1 Replies

5. Shell Programming and Scripting

Using Awk specify Unusual Delimiter

# echo "size(JFJF" | awk -F"size(" '{print $1}' awk: fatal: Unmatched ( or \(: /size(/ the delimiter is "size(" but i'm not sure if awk is the best tool to use to specify it. i have tried: # echo "size(JFJF" | awk -F"size\(" '{print $1}' awk: warning: escape sequence `\(' treated as... (1 Reply)
Discussion started by: SkySmart
1 Replies

6. UNIX for Dummies Questions & Answers

Find delimiter and double quote the field

Hi I have a asterisk (*) delimited file and there are some fields which contain data having asterisk , now i want to double quote the fileds which contain data with asterisk Ex: input file ID*NAME*EMAIL 1*BILL*BILL@AOL.com 2*J*OY*JOY@msn.com in the 2nd record JOY has a asterisk value in... (11 Replies)
Discussion started by: halmstad
11 Replies

7. Shell Programming and Scripting

double quote as the delimiter

I'm trying to extract a column from a csv file with either cut or awk but some of the fields contain comma with them: "Field1","Field2, additional info","Field3",...,"Field17",... If I want to extract column 3 and use comma as the delimiter, I'll actually get the additional info bit but not... (4 Replies)
Discussion started by: ivpz
4 Replies

8. Shell Programming and Scripting

awk delimiter

I have several hundred files that look like this: ABB110405110000.rawfma8 AAB110405110001.rawhr32 If I use the statement ls | awk '{x=$0;gsub("","",x) I see that all characters other than 0-9 are eliminated but how do I eliminate all characters including numbers after the "." In my mind I... (1 Reply)
Discussion started by: rdburg
1 Replies

9. Shell Programming and Scripting

Inserting double quotes after third delimiter

Hi, I'm trying to insert double quotes right after the third delimiter in a file. Delimiter is ^Z. For example: Input: Oct ^Z 1234 ^Z John ^Z Hello!" Desired Output: Oct ^Z 1234 ^Z John ^Z "Hello!" Any ideas? (1 Reply)
Discussion started by: kangaroo
1 Replies

10. UNIX for Advanced & Expert Users

How can I use double character delimiter in the cut command

Hi All, Can the cut command have double character delimiter? If yes, how can we use it. if my data file contains : apple || mango || grapes i used cut -f1 -d"||" filename but got an error. Plz help.... Thanks. (1 Reply)
Discussion started by: AshishK
1 Replies
Login or Register to Ask a Question