- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Changing file contents using script
Operating System - HP-UX
1753835
Members
8295
Online
108806
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
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
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- 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
тАО06-11-2004 10:11 PM
тАО06-11-2004 10:11 PM
Hi,
i have a file containing 4 feilds separated by a : . This is used by application to determine the usrer rights. File look like this
user1:lp:3:FLb//*xKns:
user3:lp:0:ClbkWTlqmYY:
user4:lp:3:OyNWlqPZxxE:
user5:lp:4:XyyNpqrzT/K:
The same file existing in almost 200 systems running HP-UX 11i. Now requirement is to change the user rights in feild 3. The number varies from 0 - 4. How can i achieve this using a script. Any help is highly appriciated.
Thanks in advance
...Jag
i have a file containing 4 feilds separated by a : . This is used by application to determine the usrer rights. File look like this
user1:lp:3:FLb//*xKns:
user3:lp:0:ClbkWTlqmYY:
user4:lp:3:OyNWlqPZxxE:
user5:lp:4:XyyNpqrzT/K:
The same file existing in almost 200 systems running HP-UX 11i. Now requirement is to change the user rights in feild 3. The number varies from 0 - 4. How can i achieve this using a script. Any help is highly appriciated.
Thanks in advance
...Jag
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-11-2004 10:53 PM
тАО06-11-2004 10:53 PM
Re: Changing file contents using script
in my opinion, but I'm probably a bit prejusiced, Perl is the obvious choise
# perl -pi -aF: -e'$F[2]++;$_=join":",@F' your_file
to increment all third fields (perl counts from 0)
# perl -pi -aF: -e'$F[0]=~/9/ and $F[2]=9;$_=join":",@F' your_file
to set field 3 to 9 if the first field has a 9 in it
# perl -pi -aF: -e'$F[0]=~/6$/ and $F[2]+=4;$_=join":",@F' your_file
to add 4 to field 3 if the first field ends with a 6
# perl -pi -aF: -e'BEGIN{%u=(user2=>4,user8=>3)}exists$f{$F[0]} and $F[2]=$u{$F[0]};$_=join":",@F' your_file
to set field 3 to 4 for field1 equal to user2, field 3 to 3 for field1 equal to user8, and field 3 unchanged for all other users
Due to the -pi option, all changes are in-place, meaning there are no pipes or temporary files involved
Enjoy, Have FUN! H.Merijn
# perl -pi -aF: -e'$F[2]++;$_=join":",@F' your_file
to increment all third fields (perl counts from 0)
# perl -pi -aF: -e'$F[0]=~/9/ and $F[2]=9;$_=join":",@F' your_file
to set field 3 to 9 if the first field has a 9 in it
# perl -pi -aF: -e'$F[0]=~/6$/ and $F[2]+=4;$_=join":",@F' your_file
to add 4 to field 3 if the first field ends with a 6
# perl -pi -aF: -e'BEGIN{%u=(user2=>4,user8=>3)}exists$f{$F[0]} and $F[2]=$u{$F[0]};$_=join":",@F' your_file
to set field 3 to 4 for field1 equal to user2, field 3 to 3 for field1 equal to user8, and field 3 unchanged for all other users
Due to the -pi option, all changes are in-place, meaning there are no pipes or temporary files involved
Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-11-2004 11:26 PM
тАО06-11-2004 11:26 PM
Solution
Hi,
You can try with awk as well:
TMP=/tmp/$$
awk -F: {$3=whatyouneed;print}' $SOURCE |sed 's/ /:/g'>$TMP
cp $TMP $SOURCE
Naturally, you will have to define the variable "whatyouneed" according to your needs.
HTH
You can try with awk as well:
TMP=/tmp/$$
awk -F: {$3=whatyouneed;print}' $SOURCE |sed 's/ /:/g'>$TMP
cp $TMP $SOURCE
Naturally, you will have to define the variable "whatyouneed" according to your needs.
HTH
Entities are not to be multiplied beyond necessity - RTFM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-12-2004 05:40 AM
тАО06-12-2004 05:40 AM
Re: Changing file contents using script
userid="user1"
uperms=2
if (( $uperms > -1 && $uperms < 5 )) ;then
ex -s -c "s/\(^$userid:.*:\)[0-4]/\1$uperms/ |wq" yourfile
fi
you might want to make a back up copy of your file before making your modification just in case
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP