Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

Subject: script to combine data from 2 files

Original Message
Name: badger
Date: April 6, 2008 at 13:58:57 Pacific
Subject: script to combine data from 2 files
OS: Mac OSX
CPU/Ram: N/A
Model/Manufacturer: N/A
Comment:
Hi,
I'm trying to combine columns of data from two text files. I'd like to take every line of column 2 from text file A and every line of column 3 from text file B. Then write every combination of lines in the two columns to a new text file. So for instance if there were 4 lines in each column from the old files, then the new file would contain 4x4 = 16 lines, each with 2 columns. Any advice or help on this would be greatly
appreciated.

b


Report Offensive Message For Removal

Response Number 1
Name: ghostdog
Date: April 6, 2008 at 18:08:53 Pacific
Subject: script to combine data from 2 files
Reply: (edit)
show sample input and output

Report Offensive Follow Up For Removal

Response Number 2
Name: FishMonger
Date: April 6, 2008 at 21:13:07 Pacific
Subject: script to combine data from 2 files
Reply: (edit)
Who's going to get the credit for your homework assignment if we do it for you? If you want to get an "A" in the class, then you should ask your instructor to provide you with the answers, that way you know you'll be submitting the answer that he/she wants.

Report Offensive Follow Up For Removal

Response Number 3
Name: ghostdog
Date: April 6, 2008 at 23:15:06 Pacific
Subject: script to combine data from 2 files
Reply: (edit)
wow, fm, you are in a bad mood today :)

Report Offensive Follow Up For Removal

Response Number 4
Name: badger
Date: April 7, 2008 at 06:11:30 Pacific
Subject: script to combine data from 2 files
Reply: (edit)
Here is a sample of what I'd like to do. Files A and B are both space delimited text files.

File A:

1 event1
2 event2
3 event3
4 event4

File B:

Smp 2007 Station1
Smp 2007 Station2
Smp 2007 Station3
Smp 2007 Station4

Output text file:

event1 station1
event2 station1
event3 station1
event4 station1
event1 station2
event2 station2
event3 station2
event4 station2
event1 station3
event2 station3
event3 station3
event4 station3
event1 station4
event2 station4
event3 station4
event4 station4

Thank you for any help. Also Fishmonger this is for my research, not for a class. I hope to learn from you guys.

b


Report Offensive Follow Up For Removal

Response Number 5
Name: lankrypt0
Date: April 7, 2008 at 06:33:36 Pacific
Subject: script to combine data from 2 files
Reply: (edit)
#!/usr/bin/ksh
for var in $(awk '{print $2}' < filea);do
for var2 in $(awk '{print $3}' < fileb);do
print $var $var2
done
done

Report Offensive Follow Up For Removal

Response Number 6
Name: lankrypt0
Date: April 7, 2008 at 06:35:59 Pacific
Subject: script to combine data from 2 files
Reply: (edit)
Forgot the explanation. Basically you are saying for every second word one every line in fila (line2) and every third word on every line in fileb (line3) print the results you find (line4).

Report Offensive Follow Up For Removal

Response Number 7
Name: badger
Date: April 7, 2008 at 07:07:22 Pacific
Subject: script to combine data from 2 files
Reply: (edit)
Thanks that's a huge help.

b


Report Offensive Follow Up For Removal

Response Number 8
Name: ghostdog
Date: April 7, 2008 at 07:19:56 Pacific
Subject: script to combine data from 2 files
Reply: (edit)
well, there's no need to use awk that many times :)


NR==FNR{
a[FNR]=$2
c=FNR
next
}
{
for(i=1;i<=c;i++) {
print a[i],$3
}
}

save the above script as script.awk
on command line:


# awk -f script.awk file1 file2
event1 Station1
event2 Station1
event3 Station1
event4 Station1
event1 Station2
event2 Station2
event3 Station2
event4 Station2
event1 Station3
event2 Station3
event3 Station3
event4 Station3
event1 Station4
event2 Station4
event3 Station4
event4 Station4


Report Offensive Follow Up For Removal

Response Number 9
Name: lankrypt0
Date: April 7, 2008 at 08:47:22 Pacific
Subject: script to combine data from 2 files
Reply: (edit)
ghostdog: i really need to learn awk better =)

Report Offensive Follow Up For Removal



Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: script to combine data from 2 files

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software



Version Tracker Pro
Keep your software current and secure, effortlessly

Click Here for a Free Scan

Driver Agent
Automatically find the latest drivers for your computer.
Click Here for a Free Scan



The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC