AWK how to change delimiter while outputting

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK how to change delimiter while outputting
# 1  
Old 09-01-2009
AWK how to change delimiter while outputting

Hello I need some help in outputting Fields when the delimiter has changed:

echo "test1,test2 | test3,test4,test5" | awk -F"," '{print $1,"COUNT",$2,$4}'

prints out:
test1 COUNT test2 | test3 test5

But how to change the -F"," to -F"|" delimiter, so that it separates the
fields from $2 into the only the word test2.

in result it should print:

test1 COUNT test3 test5

How cant I do that.

brgds from
# 2  
Old 09-01-2009

If your version of awk supports regexes as FS, try this:
$ echo "test1,test2 | test3,test4,test5" | awk -F"[,|]" '{print $1,"COUNT",$2,$4}'
test1 COUNT test2  test4

# 3  
Old 09-01-2009
Originally Posted by ripat

If your version of awk supports regexes as FS, try this:
$ echo "test1,test2 | test3,test4,test5" | awk -F"[,|]" '{print $1,"COUNT",$2,$4}'
test1 COUNT test2  test4

Thanks a lot user ripat, it just works.
I didn't thought that this is so easy.

greetings from
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Change delimiter is not working using awk

I have file 2.txt and I want to change the delimiter form , to : Not sure what is the problem with below command cat 2.txt 1,a 2,b 3,d awk 'BEGIN {FS=",";OFS=":";} {print $0}' 2.txt Please use CODE tags as required by forum rules! (11 Replies)
Discussion started by: vamsi.valiveti
11 Replies

2. Shell Programming and Scripting

Perl Code to change file delimiter (passed as argument) to bar delimiter

Hi, Extremely new to Perl scripting, but need a quick fix without using TEXT::CSV I need to read in a file, pass any delimiter as an argument, and convert it to bar delimited on the output. In addition, enclose fields within double quotes in case of any embedded delimiters. Any help would... (2 Replies)
Discussion started by: JPB1977
2 Replies

3. Shell Programming and Scripting

awk :how to change delimiter without giving all field name

Hi Experts, i need to change delimiter from tab to "," sample test file cat test A0000368 A29938511 072569352 5 Any 2 for 1.00 BUTCHERS|CAT FOOD|400G Sep 12 2012 12:00AM Jan 5 2014 11:59PM Sep 7 2012 12:00AM M 2.000 group 5 ... (2 Replies)
Discussion started by: Lakshman_Gupta
2 Replies

4. Shell Programming and Scripting

Change the delimiter from Comma to Pipeline

Hello All, I need to convert a csv file to pipeline delimiter file in UNIX. The data in file itself contains comma with double qouted qualifier apart from the comma separator. Let me know how to do it. Appreciate any help if awk can be used to do it. Mentioned below is the sample record of... (14 Replies)
Discussion started by: Arun Mishra
14 Replies

5. Shell Programming and Scripting

To change the delimiter for first two columns

Dear Friends, I have file as below 1|sdf|rere|sert|trt|rtr i want to change the delimeter first three columns two fields expected output 1~sdf~rere|sert|trt|rtr Plz help (2 Replies)
Discussion started by: i150371485
2 Replies

6. Shell Programming and Scripting

awk not outputting properly

Hi Everyone, Long time lurker here. I have a project of bringing every one of our data centers to a newly enforced company standard. Standard naming conventions, domain migrations, etc. So, the people who are setting the standards are providing me with a CSV file. Column 1 has the old... (23 Replies)
Discussion started by: Zaphod_B
23 Replies

7. UNIX for Dummies Questions & Answers

How to change delimiter in my file ?

Hi I have a file in which delimiter is ';' However if the delimiter is within "" it is a part of the string and not delimiter. How to get the fields ? I want to replace the delimiter ';' to '|'. The file contains data like this : 11111; 2222 2222; 3333; 3333; 4444 ""44444 The file... (2 Replies)
Discussion started by: dashing201
2 Replies

8. Shell Programming and Scripting

awk, sed, perl assistance in outputting formatted file

Hello, Please advise. Scoured this site, as well as google for answers. However if you do not know what to search for, it's a bit hard to find answers. INPUT: ACTASS= 802 BASECOS= 279 COSNCHG= 3 CUSCOS= 52 UPLDCOS= 2 DESIRED OUTPUT: ACTASS=802 BASECOS=279 (13 Replies)
Discussion started by: abacus
13 Replies

9. Shell Programming and Scripting

Script Assistance - Outputting to file with Awk

I'm trying to take a list of domains, find out the MX resolve it to IP then find out what the NS is and output the contents to a new file. The only problem i'm having is when checking the Ip or host of the MX i can only get it to print the column with the MX record and the results of the host... (1 Reply)
Discussion started by: spartan22
1 Replies

10. Shell Programming and Scripting

Pivot variable record length file and change delimiter

Hi experts. I got a file (500mb max) and need to pivot it (loading into ORCL) and change BLANK delimiter to PIPE |. Sometimes there are multipel BLANKS (as a particular value may be BLANK, or simply two BLANKS instead of one BLANK). thanks for your input! Cheers, Layout... (3 Replies)
Discussion started by: thomasr
3 Replies
Login or Register to Ask a Question