How do i use SED command to replace the last existance of ',' with a blank value OR CUT can also do??
Eg --> aaa,aaad,fsdfde,
I want to replace it with
aaa,aaad,fsdfde
Thanks in Advance
How do i use SED command to replace the last existance of ',' with a blank value OR CUT can also do??
Eg --> aaa,aaad,fsdfde,
I want to replace it with
aaa,aaad,fsdfde
Thanks in Advance
You can use this code:
sed 's/[,]$//g' file_name
hope it will work for you
regards,
Sanjay
Thanks for your help
But i want to replace it in a variable that is runnig in a loop
Can i do that??
sed 's/[,]$//g' $valid_categorie
$valid_categorie is the variable that is used.
You can do this with your shell parameter expansion
$ var="aaa,aaad,fsdfde,"
$ echo ${var%*,}
aaa,aaad,fsdfde
Hi
Thanx for ur help
I am getting the required o/p
But can i do it without echo..
I do not want to print the values..
I am not getting the o/p when i remove "echo"
you can assign it to a variable without echo
using sed.
if we escape the "," and -i option is affect the file
sed -i s/\,$//g input-file-name
No need to escape the "," also the global option is at best superfluous:
sed 's/,$//' infile
or:
echo ${var%,}