Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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

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.

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 event4File B:
Smp 2007 Station1
Smp 2007 Station2
Smp 2007 Station3
Smp 2007 Station4Output 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 station4Thank you for any help. Also Fishmonger this is for my research, not for a class. I hope to learn from you guys.
b

#!/usr/bin/ksh
for var in $(awk '{print $2}' < filea);do
for var2 in $(awk '{print $3}' < fileb);do
print $var $var2
done
done

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).

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

Hi,
I also need to combine data 2 txt file become 1 txt file..but not using command prompt copy.
example :
text file 1
row 1 : a,b,c,,e,f,,h
row 2 : 1,2,3,,5,6,,8text file 2
row 1: ,,,d,,,g,
row 2: ,,,4,,,7,I need in 1 txt file :
row 1 : a,b,c,d,e,f,g,h
row 2 : 1,2,3,4,5,6,7,8anyone can help me ?
thanks

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |