Add n characters at end of line depending on character count for line
Hello,
I have a flat file where I expect to have 5 values delimited by 4 commas ",' : agf,sdya,geg,fgd,gdfgr but sometimes I have the following: agf,sdya,geg,fgd agf,sdya,geg agf,sdya agf For those lines, I wanna append commas at the end of the lines in order to always have a total of 4 commas: agf,sdya,geg,fgd, agf,sdya,geg,, agf,sdya,,, agf,,,, The following awk command already gives me the count number of "," for each line: awk -F\, '{print NF-1}' "MyFile" But I am not sure where to go from there. Basically I want to do the following; If CommaCount For CurrentLine != 4 Then Append(4 - "number of commas found')CommasToLine Else CheckNextLine. Thanks for your help ! :) |
How about:
Code:
awk -F, 'NF=5' OFS="," MyFile |
wow, gotta learn awk !
It looks so simple =) Thank you ! |
Let's hope there's never more than 5 fields on input ... :tisk:
|
Well I was only going to the requirements set :)
|
All times are GMT -5. The time now is 07:24 PM. |