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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

URGENT HELP REQUESTED: NEW USER

Status
Not open for further replies.

vsiva

Programmer
Nov 12, 2002
2
US
file1:
ABC,10,10/15/2002
XYZ,20,10/20/2002

file2:
11/14/2002
11/15/2002
11/16/2002

I need to write a script such that for every line in file2, I need to have an output as below:

Output file:
ABC,10,10/15/2002,11/14/2002
ABC,10,10/15/2002,11/15/2002
ABC,10,10/15/2002,11/16/2002
XYZ,10,10/15/2002,11/14/2002
XYZ,10,10/15/2002,11/15/2002
XYZ,10,10/15/2002,11/16/2002
 
This is untested, but should get you started.

awk -f test.awk file1 > output-file

# ------ test.awk ------

BEGIN {
if (!fn) fn="file2"
while ((getline < fn) > 0) {
ix++
a[ix] = $0
}
}
{
for (j=1;j<=ix;j++) print $0 a[j]
} CaKiwi
 
Worked great. Thanks. However, how do i format the output data to be csv de-limited. Input will be greatly appreciated.

Thanks

Siva
 
Replace

for (j=1;j<=ix;j++) print $0 a[j]

with

for (j=1;j<=ix;j++) print $0 &quot;,&quot; a[j]
CaKiwi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top