INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Help Using AWK output as variables

Help Using AWK output as variables

(OP)
Hi all,

I am writing to write a script that will help me with track my students absences a little better. Essentially, I have a text file with the following information:

Filename: Students.in
StudenName1 ClassName DateMissed
StudenName2 ClassName DateMissed
StudenName3 ClassName DateMissed
StudenName4 ClassName DateMissed


Where I am struggling is using AWK to come up with a text file like this:

File name: Students.out

"This is to inform you that StudentName, was absent from ClassName on DateMissed"

What's the best way to turn each field from Students.in into a variable that can be used in Students.out?

Any help is greatly appreciated!

RE: Help Using AWK output as variables

By 'each field' do you mean 'each line' with the student name being the identifying/correlating factor? If so, I would say that a perl or python script to write the documents would be a better solution than AWK would be

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

RE: Help Using AWK output as variables

(OP)
I actually mean each object for example StudentName = Field1, ClassName = Field 2, DateMissed = Field 3. Hmm... I guess I can look a the Python route, just though AWK would have been the easiest route.

RE: Help Using AWK output as variables

okay, just so I/we understand exactly what you want, or are trying to achieve ;

You want to create a separate "form letter" for every line in the original list, with the column data replacing 'place holders' in the 'boilerplate' text of the letter.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

RE: Help Using AWK output as variables

Not sure why AWK is needed. Simple shell script can do it...

CODE

#!/bin/ksh

cat Students.in | while read STUDENT CLASS DATE
do
print "This is to inform you that ${STUDENT}, was absent from ${CLASS} on ${DATE}"
done > Students.out

This seems "the easiest route" to me.

RE: Help Using AWK output as variables

(OP)
@SamBones You're absolutely right! I was over complicating things by not thinking outside the box and trying to manipulate the text with awk. Thanks for steering me in the right direction!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close