editing string using sed or grep

1

first of all please execuse my ignorance on UNIX. I am quite new.

I have lot many sql files that contains following string

${DB_USERNAME}.${TABLE_NAME}

Can anyone please tell me how could I change it in each file so that it remains only

${TABLE_NAME}

I have tried following pattern of sed.

sed 's/^[^\.]\+\.//'

But it returns only ".".

Please tell me whole combination of grep and sed.

I need to change files directly. As I think we should pipe output of grep to sed. remember I am on AIX

Ahmad

Posted 2014-02-12T10:17:57.430

Reputation: 199

Answers

2

Why so complicated? If you only want to remove the specific part:

sed 's/${DB_USERNAME}.//g' < input-file > output-file

If you want to go with something like your original expression:

sed 's/^[^\.]*\.//g' < input-file > output-file

slhck

Posted 2014-02-12T10:17:57.430

Reputation: 182 472

Thanks. that works but I need to change files directly. As I think we should pipe output of grep to sed. – Ahmad – 2014-02-12T11:12:22.177

If you need to change the file directly use in-place editing: sed -i '' -e 's/…//g' input-file or sed -i -e 's/…//g' input-file depending on your sed version. – slhck – 2014-02-12T11:16:19.423

I am on AIX.:(.. – Ahmad – 2014-02-12T11:17:24.967

1

If your sed does not support in-place editing, simply use an intermediate file. Or use sponge from Moreutils with sed -e … file | sponge file.

– slhck – 2014-02-12T11:19:54.523