replace last character in a line with sed
I am trying to replace the last character in a line with the same character plus a quotation m开发者_StackOverflow社区ark '
This is the sed code
sed "s/\([A-Za-z]\)$/\1'/g" file1.txt > file2.txt
but does not work. Where is the error?
try:
sed "s/\([a-zA-Z]\)\s*$/\1\'/" file
This will replace the last character in the line followed by none or many spaces.
HTH Chris
It seems pointless to replace a character with itself, so try this: for lines ending with a letter, add a quote to the end:
sed "/[a-zA-Z]$/s/$/'/"
This does what you ask for:
sed "s/\(.\)$/\1'/" file1.txt > file2.txt
Your line only matches a line with a single character. Note that the s
operation only takes effect if the line matches, not if only a subset of the line matches the regex.
精彩评论