Unix_Guy
Unix_Guy

Reputation: 1

What does the following sed command do: sed -i "s/,$//' <filename>

I'm new to sed.

Can someone explain what sed -i "s/,$//' means?

Upvotes: 0

Views: 143

Answers (1)

Mathieu
Mathieu

Reputation: 9629

Your regex doesn't seems correct, the good writting could be:

sed -i 's/,$//' "filename"

I replaced the opening double quote (") by a simple (')

Let's explain:

  • -i in place: the file given in argument will be changed.
  • s substitute: s/pattern/string/ it a replacement regex, matched pattern will be replaced with string
  • the pattern: ,$: will match quote (,) followed by a line feed (\n)
  • the replacement string (empty): : the pattern will be simply deleted.

So you sed command will transform a file like

a,b,c,
e,f,g
h,i,j,,

into

a,b,c
e,f,g
h,i,j,

Upvotes: 1

Related Questions