- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: AWK number range
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
Discussions
Discussions
Discussions
Forums
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
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
тАО03-07-2011 12:11 PM
тАО03-07-2011 12:11 PM
PASSLENGTH=8
Currently I am accomplishing this with the following below:
awk '{sub(/PASSLENGTH=6|PASSLENGTH=5|PASSLENGTH=4/,"PASSLENGTH=8")};{print}' ${CHG_FILE} > ${CHG_FILE}.tmp
mv ${CHG_FILE}.tmp ${CHG_FILE}
What I need to know is if there is a way to specify a range, or tell it instead that if the value for PASSLENGTH is 0=7, then take action?
Don't worry, when I pick up the kids today, I will be at the book store getting an awk reference book.
Solved! Go to Solution.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-07-2011 12:26 PM
тАО03-07-2011 12:26 PM
Re: AWK number range
awk '
{
sub(/PASSLENGTH=[0-7][^0-9]/,"PASSLENGTH=8")
print}'
If it is a two digit number, it will fail if you have 07.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-07-2011 02:42 PM
тАО03-07-2011 02:42 PM
Re: AWK number range
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-07-2011 02:46 PM
тАО03-07-2011 02:46 PM
SolutionAny optional spaces or line comments to deal with?
You could tell awk to
- first look for lines starting with PASSLENGTH
- split into an array of words around =
- compare the second word with 8
- force fresh $0 line if less than 8
- print $0
$ awk '/^PASSLENGTH=/{ split ($0,a,/=/); if (a[2] < 8) $0 = a[1] "=8"} {print}' tmp.txt
example input/output below.
Hein
$ cat tmp.txt
PASSLENGTH=12
PASSLENGTH=18
PASSLENGTH=06
PASSLENGTH=6
xxxxxENGTH=6
PASSLENGTH=08
PASSLENGTH=0
PASSLENGTH=2
PASSLENGTH=10
---- output ----
PASSLENGTH=12
PASSLENGTH=18
PASSLENGTH=8
PASSLENGTH=8
xxxxxENGTH=6
PASSLENGTH=08
PASSLENGTH=8
PASSLENGTH=8
PASSLENGTH=10
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-07-2011 03:13 PM
тАО03-07-2011 03:13 PM
Re: AWK number range
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-07-2011 10:04 PM
тАО03-07-2011 10:04 PM
Re: AWK number range
Possibly you only had one digit, this works a little better:
sub(/PASSLENGTH=[0-7]$/,"PASSLENGTH=8")
But as with Hein's example, it is better to get that number than try to pattern match the possibly two digits.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-08-2011 05:40 AM
тАО03-08-2011 05:40 AM