[SOLVED]Problem character using sed.

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
buteman
Level 4
Level 4
Posts: 331
Joined: Tue Nov 29, 2011 5:36 pm
Location: North Lincolnshire

[SOLVED]Problem character using sed.

Post by buteman »

I have a number of html files from which I am trying to create csv files. I have tried a lot of options but the content of the files do alter each month. In my search I came across the use of sed which I have never used before. Well I have made some progress having seen a number of examples but have hit a wall with one part I am trying to alter.
I cannot work out the syntax for removing a piece of text and I think it's due to one of the characters.
<td style='border:1px solid black
I believe it's the ' character
I tried splitting it up as I thought I could escape it with \ but it doesn't work.

Code: Select all

cat ab.ht |sed 's/\'border//Ig'> ab.l

> '
sed: -e expression #1, char 14: unknown option to `s'
 
For some reason the complete section is
<td style='border:1px solid black>
but the final > appears in the next cell when viewed from Libreoffice calc
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
xenopeek
Level 25
Level 25
Posts: 29614
Joined: Wed Jul 06, 2011 3:58 am

Re: Problem character using sed.

Post by xenopeek »

That doesn't work because single quoting in the shell reads all characters literally; no escape codes.

The alternative is to use double quoting so you can put a literal single quote in it:
sed "s/'border//Ig"

Or to use ANSI C quoting so you can use the \' escape sequence you used:
sed $'s/\'border//Ig'

Or you mix single and double quoting:
sed 's/'"'"'border//Ig'

See this section of the manual for explanations: https://www.gnu.org/software/bash/manua ... ml#Quoting
Image
buteman
Level 4
Level 4
Posts: 331
Joined: Tue Nov 29, 2011 5:36 pm
Location: North Lincolnshire

Re: [SOLVED]Problem character using sed.

Post by buteman »

Thanks xenopeek did double quoting and that fixed it
Locked

Return to “Scripts & Bash”