0

I need help removing special characters from the beginning of the word in a Unix shell.

For example I have the list of words like this,

'aaa
'bbb
'ccc
'ddd

I want to remove the quotes and get output like this,

aaa
bbb
ccc
ddd

How can I remove only the quote at the beginning of each word?

Edward Minnix
  • 2,889
  • 1
  • 13
  • 26
Narmatha
  • 3
  • 1

2 Answers2

1

You will need to match at a word boundary, which is delimited with \b.

So for example, if you were using sed and wanted to remove a single quote ' at the beginning of any word, you would use

sed "s/'\b//g"

Which means "replace any single quote immediately before a word boundary with an empty string".

Additionally, if you aren't worried about at the beginning of the line, you can use the specifier ^, which matches the start of a line.

sed "s/^'//g"
Edward Minnix
  • 2,889
  • 1
  • 13
  • 26
0

Give a try to:

echo 'aaa 'bbb 'ccc 'ddd | tr -d "'"
nbari
  • 25,603
  • 10
  • 76
  • 131
  • this may do something else than OP asked. I feel the other answer is better, the `\b` one. – Kent Aug 03 '18 at 13:20
  • This will only work if the quotes only appear at the beginning of words. Otherwise, If you have something like `'I don't have one` will become `I dont have one` instead of `I don't have one` – Edward Minnix Aug 03 '18 at 13:22