Hi Gurus,
I have a txt file. some record missed 2nd colum value, I need put default value into the file.
ex: below file, first 4 records, missed one column (only 4 columns. it should be 5)
$cat missedfield
aaa,bbb,ccc,fff
aaa,bbb,ccc,ddd
111,222,333,444
111,222,333,444
111,222,333,444,555
I tried awk command as below:
the problem is I want to if NF<5 and $NF>2, $2='xxx'(default value), then assign $2 to $3 and so on. but below code the column value is minused.
awk -F"," '{if (NF< 5 && $NF>2) {$2="XXX"}{ $NF=$NF-1} {print $0}}' missedfield
Can anybody help me this?
Thanks in advance.