LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-26-2012, 05:20 AM   #1
deswarf
LQ Newbie
 
Registered: Jan 2012
Posts: 26

Rep: Reputation: Disabled
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?
 
Old 01-26-2012, 05:23 AM   #2
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Rep: Reputation: 210Reputation: 210Reputation: 210
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.
 
1 members found this post helpful.
Old 01-26-2012, 05:55 AM   #3
deswarf
LQ Newbie
 
Registered: Jan 2012
Posts: 26

Original Poster
Rep: Reputation: Disabled
big thanks! it really works
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Script to traverse into sub-directory and replace line of file inside zip Marshalle Linux - General 2 08-28-2010 12:38 AM
bash script and grep inside file? agrinog Programming 3 04-02-2010 03:26 PM
using su inside a bash file elie nasrani Linux - Newbie 3 08-22-2007 10:10 PM
file:// URI to regular filename in bash matthewg42 Linux - Software 5 09-26-2006 08:12 AM
How do i change spaces inside a txt file, and replace space with backslash \? repolona Linux - Newbie 1 05-24-2006 06:08 AM


All times are GMT -5. The time now is 07:52 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration