I need to split a csv string into an array, and cut the content of its elements to a lngth or 300 if the element's content exceed the 300 characters. I'm very close to it but for some reason that i cant figure out, this is not working:
awk '{split($0,fields,",")
for(field in fields)
if(length(fields[field]) >300){
gsub(fields[field],substr(fields[field],0,300),$0)
} print
}' file_in.csv > file_out
I can see it when i run this test:
awk '{split($0,fields,","); for(field in fields) if(length(fields[field]) >=301){print fields[field]} }' file_out
This is still prnting some fields Any idea whats wrong with my awk?
gsubin such a case, because characters?and` are interpreted as special characters (resp. wildcard and escape next one). Instead call onlysubstr`.gsuborsub...substris enough to get the correct output.