Good time to use AWK?
Hi all -
I need to get minimal information from many many files. This is from our e-mail system, and each person has a file called account.settings which contains the following: Code:
{ The information I need is: username, first name, last name & password. What is the easiest possible way to do this? Is awk/sed an option? |
This little script run in the directory that contains the *.macnt directories should isolate the information you want.
Code:
#!/bin/bash |
Or in awk
Code:
$ ls Cheers, Tink |
Tinkster wins!
A very neat and instructive one liner. My congratulations. I knew awk could do it, but, being a coward, rather than spend the time that it would take me to produce that, I would clean up the output from my script in a text editor. |
awk is a great tool, well worth knowing.
The perl programming-language "ascended from" awk, and proceeded to the next galaxy. It is well worth the time to become at-least cursorily familiar with the cornucopia of power-tools that are available in Linux... all for free. Bear in mind that you will never complete the task. |
Quote:
I hate to ask another question since you've already helped out so much! But.... Is there anyway possible to get the first name and last name separatde by a comma? So they are two separate fields? Thanks! Vee |
Quote:
Will the names always come in a "First Name" "Last Name" pair, can the order vary? Are there people with first name & middle name? And here an untested variant ... it *should* take out the quotes, and replace the separating space in the name with a comma and a space. Code:
find -type d -name \*.macnt -exec awk -vdir={} 'BEGIN{FS="[=;]";printf "%s,", gensub( /..([a-z]+).macnt/, "\\1", 1, dir)}/RealName/{name=gensub(/ /, ", ", "g", gensub(/"/, "", "g", $2))}/ Password/{pwd=$2}END{printf "%s,%s\n",name,pwd}' {}/account.settings \; Cheers, Tink |
And did this do the trick?
|
Quote:
username,, first name, last name, password Those double commas I can't seem to find where it's coming from. Thanks for the help again! |
Code:
find -type d -name \*.macnt -exec awk -vdir={} 'BEGIN{FS="[=;]";printf "%s,", gensub( /..([a-z]+).macnt/, "\\1", 1, dir)}/RealName/{name=gensub(/ /, ", ", "g", gensub(/"/, "", "g", $2))}/ Password/{pwd=$2}END{printf "%s,%s\n",name,pwd}' {}/account.settings \; |
All times are GMT -5. The time now is 01:17 PM. |