- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: parsing shell variable to vi
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2003 01:45 AM
09-19-2003 01:45 AM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2003 02:12 AM
09-19-2003 02:12 AM
Re: parsing shell variable to vi
I am not able to understand your question correctly. Explain the question a little bit.
Why do you want to use a variable in a vi editor? How?
-Umapathy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2003 03:25 AM
09-19-2003 03:25 AM
Re: parsing shell variable to vi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2003 03:29 AM
09-19-2003 03:29 AM
Re: parsing shell variable to vi
I think you need to look at "sed". I have to admit, the man page for sed puts people off for a year or two before they start using it but a simple use might help you here.
sed "s/pattern/$variable/g" will look for all occurances of the pattern and replace it with the value of the variable. sed can be given a file name to look through for this pattern or it can take its standard input.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2003 04:50 AM
09-19-2003 04:50 AM
Re: parsing shell variable to vi
i have used sed to perform some of my task.
the requirement is to disable a user from the passwd file and the fields to be changed are
passwd filed to *AP*
username to Xusername
GECOS field to "disabled"
shell to /bin/false
now i have written some code using sed , i am pasting below but changes only the user field
sed -n '/^'$user1':/ {
s/'$user1'/X'$user1'/
p
}' passwd.
any help will be highly apprecialted.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2003 05:03 AM
09-19-2003 05:03 AM
Re: parsing shell variable to vi
Here is a easy to read perl script.
It takes an argument of the user name you want to change and writes it to the standard output.
#!/usr/bin/perl
open INPUTFILE,"
while($line=
chomp($line);
($login,$passwd,$uid,$gid,$gecos,$homedir,$sh)=split ":",$line;
if($login eq $ARGV[0]){
$login="X$login";
$passwd="*AP*";
$gecos="disabled";
$sh="/bin/false";
}
print "$login:$passwd:$uid:$gid:$gecos:$homedir:$sh\n";
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2003 05:05 AM
09-19-2003 05:05 AM
Re: parsing shell variable to vi
here's a skeletton script :)
awk -F":" '$1 ~ /USERNAME/ { print "X" $1 ":*AP*:" $3 } $1 !~ /USERNAME/ { print }' /etc/passwd
my example will only change the first 3 fields, but you get the idea - if first field matches you do all changes you want in there with print $field and if it does not match then you just print the line untouched. this produces an updated passwd file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2003 04:31 PM
09-22-2003 04:31 PM
Re: parsing shell variable to vi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2003 05:09 PM