in reply to in place editing by variables
"...I am focus on user1 in the script below but would also like to see a script example if I wanted to in place edit user1 and user3..."
I agree with hdb and others totally here, however, if you still want to practice with your originally Posted data as shown in your post. You can go through the line one by one substituting for user1 and user3 like so:
Output:use warnings; use strict; while(<DATA>){ chomp; if(/^user(1|3):/){ s{(?<=/bin)(.+?)$}{/nologin}; } print $_,$/; } __DATA__ user1:x:9760822:3241:USER 1:/home/user1:/bin/bash user2:x:9760822:3242:USER 2:/home/user2:/bin/ksh user3:x:9760822:3243:USER 3:/home/user3:/bin/sh
user1:x:9760822:3241:USER 1:/home/user1:/bin/nologin user2:x:9760822:3242:USER 2:/home/user2:/bin/ksh user3:x:9760822:3243:USER 3:/home/user3:/bin/nologin
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: in place editing by variables
by cp890 (Initiate) on Apr 11, 2013 at 22:06 UTC |