The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
need help in Parsing a CSV file and generate a new output file vkr Shell Programming and Scripting 15 08-01-2008 07:33 AM
Finding & Moving Oldest File by Parsing/Sorting Date Info in File Names nikosey Shell Programming and Scripting 6 07-30-2008 09:46 PM
Parsing a file (sed/awk?) aristegui Shell Programming and Scripting 10 06-25-2008 10:21 AM
Parsing xml file using Sed kapilkinha UNIX for Advanced & Expert Users 3 04-08-2008 09:43 AM
Parsing a csv file chiru_h Shell Programming and Scripting 6 02-12-2008 09:33 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-13-2008
mirusko mirusko is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 14
Parsing a file

Hi guys,
what is the easiest way in ksh to parse a file? For example I want to find out a value of MIN_PASSWORD_LENGTH from /etc/default/security and I want to make sure it has a certain value. Of course I need to make sure the line is commented out, or if the are more lines with MIN_PASSWORD_LENGTH that at least one of them is commented out ...

thanks,
Kubko
  #2 (permalink)  
Old 10-13-2008
treesloth treesloth is offline
Registered User
  
 

Join Date: Oct 2008
Location: Orem, Utah
Posts: 72
Pardon my ignorance, but what kind of system are you using? How is the /etc/default/security file structured? Let's suppose it's just a whitespace-separated table, such as:

Code:
VALUE1     <data>
VALUE2     <data>
...
...
MIN_PASSWORD_LENGTH     8
...
...
VALUEn     <data>
Then something like this might do the trick:

Code:
grep ^MIN_PASSWORD_LENGTH /etc/default/security | awk '{ if ($2 > 6) print "Value is good"; else print "Danger, Will Robinson!" }'
Alter values, messages, and possibly the awk field separator, as needed. Rinse and repeat. It might be that more information is needed to make this match the security file; just post any relevant information and I'm sure we can put something together.
  #3 (permalink)  
Old 10-14-2008
mirusko mirusko is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 14
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?

Thank you,
K
  #4 (permalink)  
Old 10-14-2008
treesloth treesloth is offline
Registered User
  
 

Join Date: Oct 2008
Location: Orem, Utah
Posts: 72
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.
  #5 (permalink)  
Old 10-14-2008
mirusko mirusko is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 14
Will, there might be more than 1 uncommented line starting with MIN_PASSWORD_LENGTH.
Other than that it looks great! Thank you so much!

K.
  #6 (permalink)  
Old 10-14-2008
treesloth treesloth is offline
Registered User
  
 

Join Date: Oct 2008
Location: Orem, Utah
Posts: 72
Quote:
Originally Posted by mirusko View Post
Will, there might be more than 1 uncommented line starting with MIN_PASSWORD_LENGTH.
Other than that it looks great! Thank you so much!
No problem. I glad it worked out. BTW, my name is Andrew, not Will. My "Danger, Will Robinson" reference was to the old "Lost In Space" television series. I guess I need to pick somewhat less obscure references.
  #7 (permalink)  
Old 10-14-2008
mirusko mirusko is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 14
sorry Andrew! :-)
What about if I have more references to MIN_PASSWORD_LENGTH in the file?
like
MIN_PASSWORD_LENGTH=4
MIN_PASSWORD_LENGTH=7
..
MIN_PASSWORD_LENGTH=x
?
How could I handle this?
Thanks again
K.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 08:32 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0