Reputation: 91
If i have a text file with comma as delimiter, how do i count delimiter and change from lower to uppercase on 3rd delimiter? If i have text file like this:
alex pallex, bakerstreet 5, 87236, ducktales, 213445
Donald Duck, weebfoot street 1313, 12345, duckburg, 212344
And i want to have upper case on string after the 3rd comma, how do i do that using sed . ducktales changes to DUCKTALES och duckburg to DUCKBURG I know there is AWk but i need to use sed.
Upvotes: 0
Views: 59
Reputation: 37414
Using awk you'd:
$ awk 'BEGIN{FS=OFS=", "}{$4=toupper($4)}1' file
alex pallex, bakerstreet 5, 87236, DUCKTALES, 213445
Donald Duck, weebfoot street 1313, 12345, DUCKBURG, 212344
Upvotes: 2
Reputation: 5252
$ cat file.txt
alex pallex, bakerstreet 5, 87236, ducktales, 213445
Donald Duck, weebfoot street 1313, 12345, duckburg, 212344
$ sed 's/\([^\,]*\,[^\,]*\,[^\,]*\,\)\([^\,]*\)/\1\U\2/' file.txt
alex pallex, bakerstreet 5, 87236, DUCKTALES, 213445
Donald Duck, weebfoot street 1313, 12345, DUCKBURG, 212344
Not sure if no escape would work, but you can try:
sed 's/\([^,]*,[^,]*,[^,]*,\)\([^,]*\)/\1\U\2/' file.txt
Anyway, it's bothersome, if you have GNU sed, PesaThe's answer is great.
Upvotes: 0