help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-bash] comma and missing


From: Val Krem
Subject: [Help-bash] comma and missing
Date: Mon, 19 Mar 2018 01:29:08 +0000 (UTC)

Hi all,
I have a file with  four variables, The variables may be separated by several 
white spaces .  All records may not have the four variables (missing 
variables).  Example of data is shown below.

Var1  Var2    var3       var4           
ZZ2  117222807   72721821  117763696
ZJ4   300341838   3417558                  
ZJ8   114816452 3436681   67107510
ZJ0   753410012  
ZJ3  127607528 67453049  67072875
Z14 

In the example  in record 2  var4 is missing, in  record 4, var3 and var4 are 
missing  and in record 6  var2, var3 and var4  are missing.

I want to produce a comma separated , accounting the missing variables too and 
the  output   should be as shown below.

Var1,Var2,var3,var4           
ZZ2,117222807,72721821,117763696
ZJ4,300341838,3417558,                  
ZJ8,114816452,3436681,67107510
ZJ0,753410012,, 
ZJ3,127607528,67453049,67072875
Z14,,, 

I tried this 
sed 's/ \{1,\}/,/g'  file1, but I did not get whet I wanted.


Any help is highly appreciated in advance



reply via email to

[Prev in Thread] Current Thread [Next in Thread]