LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 05-14-2005, 04:05 PM   #1
acidjuice
Member
 
Registered: Jan 2005
Location: a tiny spot on the iceberg
Distribution: Slackware 10.1 (dropline 2.10, kernel 2.6.11.6)
Posts: 320

Rep: Reputation: 30
find...sed...


dear all,

i'm not very familiar with this command therefore maybe someone generous can show me the begin on this.

i need to replace in a set of text files, all with extension .aj in all the subdirectories of a directory /home/main/*, the line:
Code:
MyVar=/etc/
into
Code:
MyVar=/lib/
i know i can do something like:
Code:
find ./ -name "*.aj" -exec sed -i .... {} \;
what in the ... space?

Last edited by acidjuice; 05-14-2005 at 04:13 PM.
 
Old 05-14-2005, 04:29 PM   #2
gbonvehi
Senior Member
 
Registered: Jun 2004
Location: Argentina (SR, LP)
Distribution: Slackware
Posts: 3,145

Rep: Reputation: 53
I assume that will be only one line containing that var..
the general expression to search and replace is : s/regular-expression/replacement text/{flags}
So it will be something like:
Code:
-e 's/MyVar=\/etc\//MyVar=\/lib\//'
the -e tells sed to use that as the script.

Last edited by gbonvehi; 05-14-2005 at 04:31 PM.
 
Old 05-14-2005, 04:39 PM   #3
acidjuice
Member
 
Registered: Jan 2005
Location: a tiny spot on the iceberg
Distribution: Slackware 10.1 (dropline 2.10, kernel 2.6.11.6)
Posts: 320

Original Poster
Rep: Reputation: 30
thank you,

so basically i set myself in the /home/main directory and then run
Code:
find ./ -name "*.aj" -exec sed -i -e 's/MyVar=\/etc\//MyVar=\/lib\//' {}
is this correct? what is the ./ code then?
 
Old 05-15-2005, 04:52 PM   #4
gbonvehi
Senior Member
 
Registered: Jun 2004
Location: Argentina (SR, LP)
Distribution: Slackware
Posts: 3,145

Rep: Reputation: 53
./ means the current directory.
 
Old 05-16-2005, 03:58 AM   #5
acidjuice
Member
 
Registered: Jan 2005
Location: a tiny spot on the iceberg
Distribution: Slackware 10.1 (dropline 2.10, kernel 2.6.11.6)
Posts: 320

Original Poster
Rep: Reputation: 30
thank you.
 
Old 05-17-2005, 05:01 AM   #6
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
If this is part of a script that might be started (even accidently) in a different directory you could use an absolute address; find /home/main/ instead of find ./ .

Last edited by jschiwal; 05-17-2005 at 05:03 AM.
 
Old 05-19-2005, 04:08 PM   #7
acidjuice
Member
 
Registered: Jan 2005
Location: a tiny spot on the iceberg
Distribution: Slackware 10.1 (dropline 2.10, kernel 2.6.11.6)
Posts: 320

Original Poster
Rep: Reputation: 30
using this command i get this error:
Code:
find: missing argument to `-exec
anyone know what the correct statement would be?...
 
Old 05-19-2005, 04:51 PM   #8
acidjuice
Member
 
Registered: Jan 2005
Location: a tiny spot on the iceberg
Distribution: Slackware 10.1 (dropline 2.10, kernel 2.6.11.6)
Posts: 320

Original Poster
Rep: Reputation: 30
sorry for this missed the {} \; terminal part
 
Old 05-20-2005, 08:57 AM   #9
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
If it is possible that the filenames found might contain whitespace characters, enclose the brackets in double quotes. -exec ... "{}" \;
 
  


Reply



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
sed and escaping & in something like: echo $y | sed 's/&/_/g' prx Programming 7 02-03-2005 11:00 PM
SED;find and replace;help required gd13 Programming 3 12-21-2004 06:33 AM
More SED help facets Programming 2 06-03-2004 11:02 AM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM
sed ??? nabil Programming 10 06-17-2002 06:36 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 02:21 AM.

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
Open Source Consulting | Domain Registration