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

Generating multiple files based on contents from 1 file.

Generating multiple files based on contents from 1 file.

Generating multiple files based on contents from 1 file.

(OP)
Hello, I am new to AWK and I was wondering if I can use AWK for this:

I have to generate multiple files for a performance testing task where only the filename and a string within the file would be incremented for each test file. We need to generate thousands of files which is why we are looking for an automated solution. Can I create a "master" file for this and have AWK use this file to generate all my test files? Here's what I'm thinking:

Master File contains:
1. filename = WAWF_I_002-TEST-XXXX.xml (where XXXX will be incremented for each file)
2. include a variable within the data to increment my invoice number to correspond to the filename (<Invoice_Document.Invoice_Identification.Identifier>6U02130228-XXXX</Invoice_Document.Invoice_Identification.Identifier>)
3. all remaining data to be included on each file as noted except for the invoice number (possibly surrounded by {} or any other special character to indicate the beginning and ending of the data block)

Any thoughts on this? Will this be a good approach to take? Your help with this will be greatly appreciated.
Thanks,
Gilmar

RE: Generating multiple files based on contents from 1 file.


Try something like this:

CODE

==> cat m4
# This is the master xml file, notice the text to replace is '%INVOICE%'
#
cat - <<! >master.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<document><controlData><systemName>ADMIN</systemName>
<generationUserId>ElkaBrwn01</generationUserId>
<generationDate>03172011</generationDate>
<generationTime>193800</generationTime>
<generationProcedure/>
<formType>INVOICE</formType>
<documentClass>CI</documentClass>
<Invoice_Document.Invoice_Identification.Identifier>%INVOICE%</Invoice_Document.Invoice_Identification.Identifier>
<Amount>153775.12</Amount>
<actionRequested>create</actionRequested>
!
rm WAWF_I_002-TEST-*.xml 2>&1
>MasterFile
max=3                    #<== number of files to generate
i=0
while [ i -le max ]
do
  (( i+=1 ))
  SEQNO=`printf "%04d" $i`
  OUTFILE="WAWF_I_002-TEST-${SEQNO}.xml"
  INVOICE="6U02130228-${SEQNO}"
  echo "$i - $OUTFILE $INVOICE"
  sed "s/%INVOICE%/$INVOICE/" master.xml > $OUTFILE
  echo "$OUTFILE $INVOICE" >>MasterFile
done

==> ./m4
1 - WAWF_I_002-TEST-0001.xml 6U02130228-0001
2 - WAWF_I_002-TEST-0002.xml 6U02130228-0002
3 - WAWF_I_002-TEST-0003.xml 6U02130228-0003
4 - WAWF_I_002-TEST-0004.xml 6U02130228-0004

==> l|grep WAWF
-rw-r--r--    1 oracle   dba             504 Jan 10 14:28 WAWF_I_002-TEST-0004.xml
-rw-r--r--    1 oracle   dba             504 Jan 10 14:28 WAWF_I_002-TEST-0003.xml
-rw-r--r--    1 oracle   dba             504 Jan 10 14:28 WAWF_I_002-TEST-0002.xml
-rw-r--r--    1 oracle   dba             504 Jan 10 14:28 WAWF_I_002-TEST-0001.xml
==> 
3eyes

----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

RE: Generating multiple files based on contents from 1 file.

(OP)
Hello, I tried this solution and I get the following when creating my m4 test file:

-bash: [: i: integer expression expected

Do I need to add something to my logic piece? Also, I noticed this is using SED. Does SED work as well as AWK?

Thanks,
Gilmar

RE: Generating multiple files based on contents from 1 file.

(OP)
Thanks so much that seems to work! I successfully created 4 files. I should be able to use this adding a few modifications.

Thanks again,
Gilmar

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