Sponsored Content
Top Forums UNIX for Beginners Questions & Answers How to replace line through sed , but without uncommented? Post 303041828 by foad on Wednesday 4th of December 2019 05:32:15 PM
Old 12-04-2019
Quote:
Originally Posted by RudiC
Try
Code:
sed '/^PASS_MIN_LEN/c\PASS_MIN_LEN 12' /etc/login.defs

This will work only if the setting is left-aligned, which is usually the case, but not necessarily so. Furthermore you are replacing the whole line which would delete comments within the same line, like:

Code:
PASS_MIN_LEN     10    # this is a comment

You can make that more robust by:

Code:
sed 's/^\([[:space:]]*PASS_MIN_LEN[[:space:]]\)*[0-9][0-9]*/\112/' /etc/login.defs

By the way: you know that PASS_MIN_LEN is obsoleted as it is handled by PAM nowadays, yes?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed - Replace Line which contains the Pattern match with a new line

I need to replace the line containing "STAGE_DB" with the line "STAGE_DB $DB # database that contains the table being loaded ($workingDB)" Here $DB is passed during the runtime. How can I do this? Thanks, Kousikan (2 Replies)
Discussion started by: kousikan
2 Replies

2. Shell Programming and Scripting

How to replace one line with three in sed

Hi, I have a problem. I want to use SED to replace one line with three It looks like: PARAM='first_line,second_line,third_line' And in file: blablabla blablabla PARAM blablabla blablabla blablabla All I want is to change this into: blablabla blablabla first_line second_line... (6 Replies)
Discussion started by: ch0sen
6 Replies

3. Shell Programming and Scripting

sed to replace a line with modified line in same file

i have few lines in a file... i am reading them in a while loop so a particular line is held is $line1.. consider a modified line is held in $line2.... i want to replace $line1 with $line2 in the same file... how to do it..? i have come up till the below code sed "s/$line1/$line2/g" tmpfile.sql... (5 Replies)
Discussion started by: vivek d r
5 Replies

4. Shell Programming and Scripting

I need to know how to replace a line after a pattern match with an empty line using SED

Hi How Are you? I am doing fine! I need to go now? I will see you tomorrow! Basically I need to replace the entire line containing "doing" with a blank line: I need to the following output: Hi How Are you? I need to go now? I will see you tomorrow! Thanks in advance.... (1 Reply)
Discussion started by: sags007_99
1 Replies

5. Linux

Problem editting the first occurence of a pattern in the first uncommented line

Hi I have to replace a pattern found in the first uncommented line in a file. The challenge I'm facing is there are several such similar lines but I have to edit only the first uncommented line. Eg: #this is example #/root/xyz:Old_Pattern /root/xyz:Old_Pattern /root/xyz:Old_Pattern ... (10 Replies)
Discussion started by: Stoner008
10 Replies

6. Shell Programming and Scripting

sed command to replace a line at a specific line number with some other line

my requirement is, consider a file output cat output blah sdjfhjkd jsdfhjksdh sdfs 23423 sdfsdf sdf"sdfsdf"sdfsdf"""""dsf hellow there this doesnt look good et cetc etc etcetera i want to replace a line of line number 4 ("this doesnt look good") with some other line ... (3 Replies)
Discussion started by: vivek d r
3 Replies

7. Shell Programming and Scripting

Multiple line search, replace second line, using awk or sed

All, I appreciate any help you can offer here as this is well beyond my grasp of awk/sed... I have an input file similar to: &LOG &LOG Part: "@DB/TC10000021855/--F" &LOG &LOG &LOG Part: "@DB/TC10000021852/--F" &LOG Cloning_Action: RETAIN &LOG Part: "@DB/TCCP000010713/--A" &LOG &LOG... (5 Replies)
Discussion started by: KarmaPoliceT2
5 Replies

8. Shell Programming and Scripting

sed command to replace a line in a file using line number from the output of a pipe.

Sed command to replace a line in a file using line number from the output of a pipe. Is it possible to replace a whole line piped from someother command into a file at paritcular line... here is some basic execution flow.. the line number is 412 lineNo=412 Now i have a line... (1 Reply)
Discussion started by: vivek d r
1 Replies

9. Shell Programming and Scripting

Replace values in script reading line by line using sed

Hi all, Let's say I have a script calling for the two variables PA_VALUE and PB_VALUE. for pa in PA_VALUE blah blah do for pb in PB_VALUE blah blah do I have a text file with two columns of values for PA and PB. 14.5 16.7 7.8 9.5 5.6 3.6 etc etc I would like to read this... (7 Replies)
Discussion started by: crimsonengineer
7 Replies

10. Shell Programming and Scripting

Hos to get the line number of uncommented line from the file

I have few lines in a text file. I am trying to get the line number of uncommented line from the text file using unix shell script. For example : I want the line number of Orange from the below text file. Here expected answer is 4 since the line 2 is commented. Apple #Orange grapes Orange (4 Replies)
Discussion started by: Brennon
4 Replies
SECURETTY(5)						     Linux Programmer's Manual						      SECURETTY(5)

NAME
securetty - file which lists terminals from which root can log in DESCRIPTION
The file /etc/securetty contains the names of terminals (one per line, without leading /dev/) which are considered secure for the transmis- sion of certain authentication tokens. It is used by (some versions of) login(1) to restrict the terminals on which root is allowed to login. See login.defs(5) if you use the shadow suite. On PAM enabled systems, it is used for the same purpose by pam_securetty(8) to restrict the terminals on which empty passwords are accepted. FILES
/etc/securetty SEE ALSO
login(1), login.defs(5), pam_securetty(8) COLOPHON
This page is part of release 4.15 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at https://www.kernel.org/doc/man-pages/. Linux 2015-03-29 SECURETTY(5)
All times are GMT -4. The time now is 11:20 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy