Count characters in a csv file and add an word.

Hello,

I want to add a sentence to "post column" those who are only less than 30 characters.Thank you very much for your help.

"category","title","post" 
"Z","Zoo","test 54325 test 45363mc."
"Z","Zen","rs2w3rsj 2d342dg 2d3s4f23 d23423s23h 2s34s2423g ds232d34 2342."
"Z","Zet","test4444 dd."

output:

"category","title","post"
"Z","Zoo","test 54325 test 45363mc. Zoo is great"
"Z","Zen","rs2w3rsj 2d342dg 2d3s4f23 d23423s23h 2s34s2423g ds232d34 2342."
"Z","Zet","test4444 dd. Zet is great"

And do you want to consider , also?

Not tested this. Hope it should work.:slight_smile:

awk 'NR>1 && length($0)<30{sub("\"$","New settace \"",$0)}1' OFS="," file
awk  'BEGIN{OFS=FS="\",\""} NR>1 {if (length($3) < 30) sub("\"", " "$2" is great\"", $3)}1' file
"category","title","post" 
"Z","Zoo","test 54325 test 45363mc. Zoo is great"
"Z","Zen","rs2w3rsj 2d342dg 2d3s4f23 d23423s23h 2s34s2423g ds232d34 2342."
"Z","Zet","test4444 dd. Zet is great"
1 Like

This code works great :slight_smile: Thank you very much.