0

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

1

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
  • Thanks. that works but I need to change files directly. As I think we should pipe output of grep to sed. – Ahmad Feb 12 '14 at 11:12
  • 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 Feb 12 '14 at 11:16
  • I am on AIX.:(.. – Ahmad Feb 12 '14 at 11:17
  • 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 Feb 12 '14 at 11:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.