I have the following example of a .csv-file
"0a","1a","Short text","abc"
"0b","1bx","Here is a very long text","def"
"0c","1cx","Short text again","ghij"
And now I want to have a maximum of 16 characters in the 3rd column. So "Short text" and "Short text again" would be ok.. but "Here is a very long text" should be "Here is a very l". Even better would be "Here is a very l..."
So that text (of the 3rd column) that is too long is shortened and replaced by '...' at the end.
I found this:
sed '/^.\{0,16\}$/!d'
But this is not really what I am looking for because it extracts only the whole lines with 0-16 characters.
Maybe you have a better idea?
Here is a very l
is indeed 16 characters long, butHere is a very l...
is 19. Your "even better would be" kinda contradicts "a maximum of 16 characters". (2) I think in csv spaces outside quotes in a field are not formally allowed. The leading spaces thus may be problematic and cause data to be interpreted not in the way you want. Do you mean"0b","1bx","Here is a very long text","def"
? or are the spaces really there? or a tab? If something is there, should it be kept?