VNA
VNA

Reputation: 625

To handle multiple different de-limiter format:

Would like to know , how to hande two or multilple different de-limiter format exists in the Input file. Example: Input file de-limited by "|" and ","

Input.txt

Name|Location|Amount        |Desc|Count
aaaa|xxxxxxxx|100.000       |aaa |15 
bbbb|yyyyyyyy|1,500.000     |bbb |20
cccc|zzzzzzzz|2,324,567.000 |ccc |38
dddd|wwwwwwww|58.000        |ddd |42  

Have tried below command and un-sucessful

awk -F '|' '{OFS=",";  print $1,$2,$3,$4,$5}'  Input.txt

Output.txt

aaaa,xxxxxxxx,100.000       ,aaa ,15
bbbb,yyyyyyyy,1,500.000     ,bbb ,20
cccc,zzzzzzzz,2,324,567.000 ,ccc ,38
dddd,wwwwwwww,58.000        ,ddd ,42

Here am trying to set OFS="," and replace "," as "" if exists in the source file. Example: Input 1,500.000 to be changed as 1500.000

Desired Output.txt

Name,Location,Amount        ,Desc,Count
aaaa,xxxxxxxx,100.000       ,aaa ,15 
bbbb,yyyyyyyy,1500.000     ,bbb ,20
cccc,zzzzzzzz,2324567.000 ,ccc ,38
dddd,wwwwwwww,58.000        ,ddd ,42 

Looking for your suggestions !!!

Upvotes: 1

Views: 188

Answers (1)

SMA
SMA

Reputation: 37063

Try sed as below:

sed 's/,//g;s/|/,/g' Input.txt

Using awk, you can substitue occurance of "," before like below:

awk -F '|' '{ gsub(/,/,""); $1=$1 }1' OFS="," Input.txt

Upvotes: 1

Related Questions