Change delimiter is not working using awk


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Change delimiter is not working using awk
# 1  
Old 02-14-2018
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

Code:
cat 2.txt
1,a
2,b
3,d

Code:
awk 'BEGIN {FS=",";OFS=":";} {print $0}' 2.txt

Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 02-14-2018 at 09:49 AM.. Reason: Added CODE tags.
# 2  
Old 02-14-2018
Hello vamsi.valiveti,

Could you please try following and let me know if this helps you.
Code:
awk -F, '{$1=$1} 1' OFS=":"   Input_file

Output will be as follows:
Code:
1:a
2:b
3:d

Thanks,
R. Singh
# 3  
Old 02-14-2018
There is no change in output.I did not get expected output
# 4  
Old 02-14-2018
Quote:
Originally Posted by vamsi.valiveti
There is no change in output.I did not get expected output
It worked for me, can you check if by any chance your Input_file is having carriage characters in your Input_file? Do this cat -v Input_file if you see carriage characters then do a tr -d '\r' < Input_file > temp_file && mv temp_file Input_file then.

Let me know how it goes then.


Thanks,
R. Singh
# 5  
Old 02-14-2018
Thanks for quick reply.I can get the solution using sed command but just want to know what is the problem with my command posted in question and why it is not working?
# 6  
Old 02-14-2018
Quote:
Originally Posted by vamsi.valiveti
Thanks for quick reply.I can get the solution using sed command but just want to know what is the problem with my command posted in question and why it is not working?
If you wouldn't give us proper information how we could let you know? Without seeing your system. So did you try my previous post's commands?

Please do let us know on same.


Thanks,
R. Singh
# 7  
Old 02-14-2018
I tried cat -v 2.txt but there is no '\r'
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

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 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

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 double delimiter

Hello, an awk style question (or a stupid question... it depends on your point of view :) ) How can I write in one awk command these two ones ? $USER - `grep $USER /etc/passwd | awk -F: '{ print $5 }' | awk -F, '{ print $1 }'` Thanks gb (4 Replies)
Discussion started by: gogol_bordello
4 Replies

9. Shell Programming and Scripting

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... (2 Replies)
Discussion started by: sdohn
2 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