LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   bash: how to replace symbols inside the file with filename (https://www.linuxquestions.org/questions/linux-newbie-8/bash-how-to-replace-symbols-inside-the-file-with-filename-925765/)

deswarf 01-26-2012 04:20 AM

bash: how to replace symbols inside the file with filename
 
hi
the question is how to replace some symbols (for example @@@) inside of the group of files with its filenames?
i supposed that it should be something like this:

for i in *
do sed 's/^@@@=.*/$i/g' $i
done

but such a cycle writes just symbols "$i" not the filename.
is such a solving possible in general without making any complicated scripts?

jhwilliams 01-26-2012 04:23 AM

If you are trying to use a bash variable with sed, and that is your problem, use double quotes instead of single quotes.

E.g.

Code:

search=foo
replace=bar
target=baz.txt
sed -i "s/$search/$replace/" $target

Will work as expected.

deswarf 01-26-2012 04:55 AM

big thanks! it really works :)


All times are GMT -5. The time now is 05:09 PM.