LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 08-30-2007, 09:42 AM   #1
mijohnst
Member
 
Registered: Nov 2003
Location: Huntsville, AL
Distribution: RHEL, Solaris, OSX, SuSE
Posts: 419

Rep: Reputation: 31
Sed - change some thing but not all


I love sed...that being said...

I'm trying to figure out a command that will change one line, but not the comment above the line I'm changing... I know it's something simple.

# PASS_MAX_DAYS sets maximum password days

PASS_MAX_DAYS 999999

So I use:

Code:
sed '/#/!s|PASS_MAX_DAYS|PASS_MAX_DAYS    180|g' /etc/login.defs
It's working kind of... but the out put looks like this:

PASS_MAX_DAYS 180 999999

Am I missing a switch somewhere? I guess I want to replace the line and the spaces are throwing me off. Thanks again!
 
Old 08-30-2007, 10:32 AM   #2
radoulov
Member
 
Registered: Apr 2007
Location: Milano, Italia/Варна, България
Distribution: Ubuntu, Open SUSE
Posts: 212

Rep: Reputation: 38
Code:
sed 's/^PASS_MAX_DAYS *[0-9]*/PASS_MAX_DAYS    180/'
 
Old 08-30-2007, 01:04 PM   #3
mijohnst
Member
 
Registered: Nov 2003
Location: Huntsville, AL
Distribution: RHEL, Solaris, OSX, SuSE
Posts: 419

Original Poster
Rep: Reputation: 31
Thanks for the reply Radoulov. That command you just sent does the same thing though. It doesn't remove the 99999.
 
Old 08-30-2007, 01:15 PM   #4
radoulov
Member
 
Registered: Apr 2007
Location: Milano, Italia/Варна, България
Distribution: Ubuntu, Open SUSE
Posts: 212

Rep: Reputation: 38
Quote:
Originally Posted by mijohnst View Post
Thanks for the reply Radoulov. That command you just sent does the same thing though. It doesn't remove the 99999.
Could you post the output from the following command?

Code:
echo "# PASS_MAX_DAYS sets maximum password days

PASS_MAX_DAYS 999999"|sed 's/^PASS_MAX_DAYS *[0-9]*/PASS_MAX_DAYS    180/'
This is the output I get:

Code:
zsh 4.3.2% echo "# PASS_MAX_DAYS sets maximum password days

PASS_MAX_DAYS 999999"|sed 's/^PASS_MAX_DAYS *[0-9]*/PASS_MAX_DAYS    180/'
# PASS_MAX_DAYS sets maximum password days

PASS_MAX_DAYS    180
zsh 4.3.2%
 
Old 09-01-2007, 03:36 PM   #5
mijohnst
Member
 
Registered: Nov 2003
Location: Huntsville, AL
Distribution: RHEL, Solaris, OSX, SuSE
Posts: 419

Original Poster
Rep: Reputation: 31
When I type in your echo command it comes out correct, but when I point what you've done in sed to the file itself it doesn't work and I think it's looking for the 999999 number. I don't think I want to look for the 99999 either because if the system has any other number I still want it replaced. Is there a switch in sed to tell it to overwrite the whole line?

Again thanks for the help!
 
Old 09-01-2007, 04:01 PM   #6
mijohnst
Member
 
Registered: Nov 2003
Location: Huntsville, AL
Distribution: RHEL, Solaris, OSX, SuSE
Posts: 419

Original Poster
Rep: Reputation: 31
Thanks for the help radoulov.... I figured it out with your help.

Code:
sed '/^PASS_MAX_DAYS/ c\PASS_MAX_DAYS   180' /etc/login.defs
The c\ will allow you to change the line to the end.
 
1 members found this post helpful.
  


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
bash script with grep and sed: sed getting filenames from grep odysseus.lost Programming 1 07-17-2006 11:36 AM
sed - the most confusing thing I have ever had to do drkstr Slackware 3 07-13-2006 12:37 PM
sed directory change "/" nachtfalter Programming 4 10-04-2004 12:35 PM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM
NEED HELP with ----draksec---- it wont let me change any thing Soggy Linux - Security 4 10-14-2003 12:39 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:28 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
Open Source Consulting | Domain Registration