Computing.Net > Forums > Unix > Simple text file parsing?

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Simple text file parsing?

Reply to Message Icon

Name: kagetto
Date: January 18, 2004 at 11:13:58 Pacific
OS: red hat 9
CPU/Ram: Athlon 1300mhz 512mb
Comment:

I need to parse a simple text file of the following format.

email@blah.com username1
email2@blah.com username2

email6@monkey.com username3

The file has a variable number of spaces between the email and username and may or may not have blank lines. I just need to run through it and store the email and username into variables so I can email that person and then loop through to the next email address. Thanks for any help.




Sponsored Link
Ads by Google

Response Number 1
Name: James Boothe
Date: January 18, 2004 at 11:40:57 Pacific
Reply:

In the solution below, awk will process only lines that have 2 or more fields (delimited by any amount of white space) and field1 must contain an at-sign, and creates lines in the format of:

  email=email@blah.com uname=username1

Then those lines are piped to a while-loop for processing.

awk '\
NF>1 && $1~"@" \
  {print "email=" $1 " uname=" $2}
' infile.txt |
while read line
do
eval $line
echo "email=$email uname=$uname"
# (generate mail here)
done


0

Response Number 2
Name: kagetto
Date: January 18, 2004 at 12:23:51 Pacific
Reply:

Awesome thank you!


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Simple text file parsing?

Shell script for Text file parsing www.computing.net/answers/unix/shell-script-for-text-file-parsing/4388.html

Reading text file in Bourne Shell www.computing.net/answers/unix/reading-text-file-in-bourne-shell/4445.html

Parsing and emailing a text file www.computing.net/answers/unix/parsing-and-emailing-a-text-file-/6623.html