Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help Using AWK output as variables 1

Status
Not open for further replies.

Corelli

Technical User
Sep 2, 2015
3
0
0
CA
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!
 
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
 
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.
 
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
 
Not sure why AWK is needed. Simple shell script can do it...

Code:
#!/bin/ksh

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

This seems "the easiest route" to me.
 
@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!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top