Reputation:
A csv file whose format is
name age comments
John 12 Hello World,Example
Jack 14 Hello,World
How to replace commas present in comment section with |(pipeline) symbol.
Commas can be present in name, age, and comments too. How to handle it dynamically within a text??
Upvotes: 0
Views: 477
Reputation: 10039
# any separator char but `/\.&[]` (or need to change the sed action), here `;`
Separator=";"
sed -e ":a
s/\(${Separator}[^${Separator}]*\),\([^${Separator}]*\)$/\1|\2/
ta" YourFile
Posix version so --posix
on GNU sed
Upvotes: 0
Reputation: 247240
Since you don't appear to be using commas as the field separator, it's as simple as
sed 's/,/|/g' file
To replace only in comments field:
while read name age comments; do echo "$name $age ${comments//,/|}"; done < file
Upvotes: 2