user3486773
user3486773

Reputation: 1246

Removing single quote on it's own in bash script without removing other single quotes?

I have file that has data that looks like this:

$table_prefix = 'wp_';
'
$more_stuff = 'ab_';
'

where randomly there is a single quote on a line by itself. I'm struggling on how to remove this while not impacting the other quotes?

I've tried sed:

sed -i -z "s/'\n/""/g" wp-config.php

Looking for ' and newline and then replacing with nothing or I don't mind if it's even replaced with a space.

Upvotes: 1

Views: 62

Answers (2)

Ryszard Czech
Ryszard Czech

Reputation: 18611

Use

sed -i 's/\r$//g' wp-config.php
sed -i "/^'$/d" wp-config.php
  • sed -i 's/\r$//g' wp-config.php - removes all carriage return characters that have a line feed after them
  • sed -i "/^'$/d" wp-config.php - removes all lines with standalone apostrophes.

Upvotes: 0

Beta
Beta

Reputation: 99084

sed -i "s/^'$//" wp-config.php

or

sed -i "/^'$/d" wp-config.php

(I advise you to try it without -i first, to make sure it does what you expect in your version of sed.)

Upvotes: 1

Related Questions