LinuxQuestions.org
Social Bookmarking all things Linux and Open Source
Go Back   LinuxQuestions.org > Forums > Linux > Linux - General
User Name
Password
Linux - General This forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Tags used in this thread
Popular LQ Tags , ,

Reply
 
Thread Tools
Old 08-14-2008, 06:51 PM   #1
khill
LQ Newbie
 
Registered: Aug 2008
Posts: 3
Thanked: 0
help with sed


[Log in to get rid of this advertisement]
hey, I need a bit of help using the command sed

what I want to do is include in a script a line which changes the umask inside of a user's .bashrc

from some searching, I think i'm 90% of the way there with:

Code:
grep umask .bashrc | sed 's/$1/umask 027/g' .bashrc
obviously the above doesn't work. So, how do I get sed to recognize the piped output of grep and include it in a replace?
khill is offline  
Tag This Post , ,
Reply With Quote
Old 08-14-2008, 06:56 PM   #2
khill
LQ Newbie
 
Registered: Aug 2008
Posts: 3
Thanked: 0

Original Poster
well geez, 5 more min of searching and I answered my own question

Code:
grep umask .bashrc | sed 's/{$1}/umask 027/g' .bashrc
khill is offline     Reply With Quote
Old 08-14-2008, 07:02 PM   #3
colucix
Guru
 
Registered: Sep 2003
Location: Bologna, Italia
Distribution: OpenSUSE 11.1 CentOS 5.4 VectorLinux 6.0
Posts: 5,132
Thanked: 464
Another way is
Code:
sed -i '/umask/s%.*%umask 027%' .bahsrc
or
Code:
sed -i 's%umask ...%umask 027%' .bashrc
these work only if the line containing the umask command is unique in .bashrc, otherwise you can get unwanted results. Also note that the -i option actually changes the content of the file. You may want to do a backup copy of your .bashrc before testing.

Edit: I tested your command and does not work for me...

Last edited by colucix; 08-14-2008 at 07:06 PM..
colucix is offline     Reply With Quote
Old 08-14-2008, 07:13 PM   #4
colucix
Guru
 
Registered: Sep 2003
Location: Bologna, Italia
Distribution: OpenSUSE 11.1 CentOS 5.4 VectorLinux 6.0
Posts: 5,132
Thanked: 464
Just a little add-on: if you want to be sure that user's .bashrc files contain a unique line with the umask command, you can consider something like this:
Code:
if [ $(grep -c umask .bashrc) -eq 1 ]
then
  sed -i '/umask/s%.*%umask 027%' .bahsrc
else
  echo ".bashrc contains more than one line with umask"
  echo "check it manually"
fi
colucix is offline     Reply With Quote
Old 08-15-2008, 12:35 PM   #5
khill
LQ Newbie
 
Registered: Aug 2008
Posts: 3
Thanked: 0

Original Poster
Well, my command doesn't work within a script, but it does work directly from the command line for me... odd that it wouldn't for you colucix. I'm using centOS if you can think of any relevant differences. Anyways, because I DO want to use this line in a script I was about to post and ask about another way to do it, but you've answered my question before I asked it colucix, thanks!
khill is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

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
bash script with grep and sed: sed getting filenames from grep odysseus.lost Programming 1 07-17-2006 12:36 PM
[sed] "Advanced" sed question(s) G00fy Programming 2 03-20-2006 01:34 AM
sed ShaqDiesel Programming 8 07-24-2005 06:57 PM
sed and escaping & in something like: echo $y | sed 's/&/_/g' prx Programming 7 02-04-2005 12:00 AM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 07:12 AM


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

Main Menu
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
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration