The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




Thread: Parsing a file
View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 10-14-2008
treesloth treesloth is offline
Registered User
  
 

Join Date: Oct 2008
Location: Orem, Utah
Posts: 73
Quote:
Originally Posted by mirusko View Post
Sorry Will, it's for HP-UX so the format is
MIN_PASSWORD_LENGTH=8
how will the awk command change?
What about if there are more lines with the same name like MIN_PASSWORD_LENGTH?
In that case, all that changes is the field separator in awk. So, this:


Code:
... awk '{ if ...

becomes:


Code:
... awk -F= '{ if ...

Now, I assumed (perhaps incorrectly) that any additional lines called "MIN_PASSWORD_LENGTH" would be commented out. For example:


Code:
MIN_PASSWORD_LENGTH=7
#MIN_PASSWORD_LENGTH=2
#MIN_PASSWORD_LENGTH=3
#MIN_PASSWORD_LENGTH=6

The grep that I used accounts for that. The ^ character in the grep tells it to return those lines that start with MIN_PASSWORD_LENGTH. So, the first line of the 4 above would be returned; the other 3 would be entirely ignored. Does that do what you need, or would there be more than 1 uncommented line starting with MIN_PASSWORD_LENGTH? Post to let us know if that's the case-- I'm sure we can put something together that works.