Hi All,
My Input.txt should have always 4 columns in some cases i may not get all the 4columns data.
My requirement is if columns as not equal to 4 then append new column delimiter.
Input.txt
A,1,2
B,1,2,3
C,1
Desired output should be in below format
Output.txt
A,1,2,
B,1,2,3
C,1,,
I had tried awk '$0=$0OFS NF-1' FS=, FILENAME
Thanks in advance
---------- Post updated at 11:48 AM ---------- Previous update was at 10:35 AM ----------
Got the solution
DEFAULT=4
j=1
for i in `awk -F"," '{print NF}' Final.txt`
do
final=`awk -F"," '{if( NR == '$j' ) print $0}' Final.txt`
while [ $i -lt $DEFAULT ]
do
final=$final","
i=$(($i + 1))
done
echo "$final" > DUMMY.txt
j=$(($j + 1))
done
mv DUMMY.txt Final.txt