- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- awk/scripting problem
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
Forums
Discussions
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
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
10-18-2000 06:05 AM
10-18-2000 06:05 AM
awk/scripting problem
1:rtesd
2:refsdcsd
3:fdcsd
where $2 is to be referenced via $1. This is the passwd update section of a password retrieval utility for all our boxes. I want to replace $2 with user entered value ${newpass}. I have tried using sub() to no avail; could you assist.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2000 06:08 AM
10-18-2000 06:08 AM
Re: awk/scripting problem
i can no see what you want.
Could you post your awk/script to the forum ?
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2000 06:32 AM
10-18-2000 06:32 AM
Re: awk/scripting problem
Suppose you have a file (/tmp/test) with following contents:
1:aaaaaaa
2:bbbbbbb
3:ccccccc
And you would like to change
2:bbbbbbb
to
2:fffffff
you can execute the commands:
$ old=$1
$ new=$newvalue
$ awk -v new="$new" -v old="$old" '{ sub(old, new); print }' /tmp/test
to obtain the output
1:aaaaaaa
2:fffffff
3:ccccccc
Hope this answers your question.
Bye,
Rik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2000 07:58 AM
10-18-2000 07:58 AM
Re: awk/scripting problem
Another way:
Given your variables $OLDPW and $NEWPW:
# sed "s/$OLDPW/$NEWPW/" /original_file > /replacement_file
# mv /replacement_file /original_file
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2000 08:08 AM
10-18-2000 08:08 AM
Re: awk/scripting problem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2000 08:51 AM
10-18-2000 08:51 AM
Re: awk/scripting problem
cat file | awk -v a=$userid -v b=$newpass -FS: '{
BEGIN {
userid = a
newpass = b
}
if (/^userid/)
then
{ print $1:newpass }
else
{ print }
}' > newfile
The sub function won't work because it replaces only what it's searching for and you want to replace field $2 while keying on $1. Then, just run this and move the result over after the awk runs.
--Scott