assistance requested (sed related)


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users assistance requested (sed related)
# 1  
Old 02-02-2008
assistance requested (sed related)

I gotta write a command to change the accounts in /etc/passwd that use a shell other than the bash to bash shell. those accounts that dont use a shell shouldnt get modified. assuming all the shell programs end in sh and other programs dont. and the result should go into /etc/passwd.rev

any hint?
# 2  
Old 02-02-2008
Awk is a much less unsuitable tool for manipulating a paswd file than sed.

Also be aware that on many systems root's password is set to /sbin/sh and uses a statically compiles shell which should not be changed.

Code:
sed 's#:[^:][^:]*$#/bin/bash#' /etc/passwd

# 3  
Old 02-02-2008
Reborg,

You forget to place a colon before "/bin/bash" and it changes all lines and that's not what the OP wants.
A little fit of your the line:

Code:
sed '/.*sh$/s#:[^:][^:]*$#:/bin/bash#' /etc/passwd

A solution with awk should looks like:

Code:
awk 'BEGIN{FS=OFS=":"}$7 ~ /.*sh$/{$7="/bin/bash"}1' /etc/passwd

Regards
# 4  
Old 02-05-2008
tnx a lot,
now what if I want to limit my sed further more so that it only looks for the lines that have 144 or 275 somewhere in them?
this is what I have:
sed '/.*144.*sh$/s#:[^:][^:]*$#:/bin/bash#' /etc/passwd
how can I include both 144 and 275 before the ".*"?
tnx again
# 5  
Old 02-05-2008
Quote:
Originally Posted by metalwarrior
tnx a lot,
now what if I want to limit my sed further more so that it only looks for the lines that have 144 or 275 somewhere in them?
this is what I have:
sed '/.*144.*sh$/s#:[^:][^:]*$#:/bin/bash#' /etc/passwd
how can I include both 144 and 275 before the ".*"?
tnx again
This post looks very similiar to this one - https://www.unix.com/unix-dummies-que...#post302164089

metalwarrior, you are consistently breaking the rules by double-posting. Please refrain from doing so.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed assistance

Hello everyone. I am trying to replace sprintf(buffer, "{\"id\":1,\"method\":\"mining.update_block\",\"params\":}\n", coinid, blockhash); with sprintf(buffer, "{\"id\":1,\"method\":\"mining.update_block\",\"params\":}\n", coinid, blockhash); this is the code I was trying but is... (9 Replies)
Discussion started by: crombiecrunch
9 Replies

2. UNIX for Dummies Questions & Answers

Sed/command assistance

Hello, I'm attempting to play with sed commands again... I have a file named test1 with numbers...ex:5551234567 I run this sed on the file... cat test1 | sed 's/^/homeDnModify "/g' | sed 's/$/" "" 3/g' >test2 Im hoping it will look like this... homeDnModify "551235" "4567" ""... (5 Replies)
Discussion started by: jay11789
5 Replies

3. UNIX for Dummies Questions & Answers

Sed/command assistance

Hello all, I need some help and education creating a script. Basically I have a file with a list of numbers.. 2125554444 2124445555 I need to put them into a format that looks like this.... UQ-V8.1,2125554444,hdaudio UQ-V8.1,2124445555,hdaudio Any help would be greatly... (6 Replies)
Discussion started by: jay11789
6 Replies

4. Shell Programming and Scripting

sed newbie scripting assistance

Howdy folks, I'm trying to craft a log file summarisation tool for an application that creates a lot of duplicate entries with only a different suffix to indicate point of execution. I thought I'd gotten close but I'm clearly missing something. Here's a genericized version: A text_file... (3 Replies)
Discussion started by: mthespian
3 Replies

5. UNIX for Advanced & Expert Users

Need assistance with sed

Hi All, I need your assistance, I would like to replace all lines beginning with the word "begin" with the below text: Device | IPMB0-A | IPMB0-B Board Address |Sent SentErr %Errr |Sent SentErr ... (10 Replies)
Discussion started by: Dendany83
10 Replies

6. Shell Programming and Scripting

Need assistance with sed

Hi All, I need your assistance, I would like to replace all lines beginning with the word "begin" with the below text: Device | IPMB0-A | IPMB0-B Board Address |Sent SentErr %Errr |Sent SentErr ... (9 Replies)
Discussion started by: Dendany83
9 Replies

7. Shell Programming and Scripting

Help on sed requested

Hi I have a problem to resolve, I think sed is the best option, and I am not successful yet. Have a UNIX file which has records as of the 2 character state codes like NY NJ PA DE From the file I need to create this as a variable in the same script or another file -... (7 Replies)
Discussion started by: snair2010
7 Replies

8. Shell Programming and Scripting

Help requested for a script with sed

Hello Folks, I would very much appreciate if I could get help/suggestions on a particular sed usage. I have to write a script to take version info from a version file, compute the image name, print error if the image does not exist. The version file looks like below: " # # version.cfg #... (3 Replies)
Discussion started by: fatimap
3 Replies

9. UNIX for Advanced & Expert Users

need assistance: sed and repeating patterns

hi, I need to write a command with sed to find all the lines in a file that contain patterns of three or more characters that repeat once and put them inside perenthezes. I cannot tell sed what pattern to look for. it should find repeated patterns automatically. example:... (1 Reply)
Discussion started by: metalwarrior
1 Replies
Login or Register to Ask a Question