How to combine data from 2 file ? How to print ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to combine data from 2 file ? How to print ?
# 1  
Old 03-11-2013
How to combine data from 2 file ? How to print ?

Dear friends,

I am just trying to print data from 2 file,namely file_1.txt and file_1.dat (specific column of ROW 1)

Code:
file_1.txt
12           13        14          15        99  AMC   69  36 89
12           13        14          15        99  AMC   69  84 -12
12           13        14          15        99  AMC   69  25  56
12           13        14          15        99  AMC   69  12  25

Code:
file_1.dat
12   35
15   35
25   87
15   64

here I need col1, col3, col5, col6 from file_1.txt

I want to print like this
Code:
12 14 99 69 12 35
12 14 99 69 15 35 
12 14 99 69 25 87
12 14 99 69 15 64

I am sorting files like this,
Code:
for file in `ls *.txt |sort -t"_" -k2n,2`; do

and it should use in order say
Code:
file_1.txt and then file_1.dat

then print
# 2  
Old 03-11-2013
RedHat

Code:
awk '{print $1,$3,$5,$6} file_1.txt  > tmp
paste tmp file_1.dat

# 3  
Old 03-11-2013
I have about 100 file How do I set order in loop ?

I want like this

Code:
file_1.txt file_1.dat > output1
file_2.txt file_2.dat > output2
file_3.txt file_3.dat > output3
file_4.txt file_4.dat > output4

# 4  
Old 03-11-2013
RedHat

Code:
for i in {1..100}
do
awk '{print $1,$3,$5,$6} file_${i}.txt  > tmp_${i} 
paste tmp_${i} file_${i}.dat
rm -f tmp_${i}
done

bash guys are smarter they can give you a better replacement.

I am an ugly old korn guy Smilie
# 5  
Old 03-11-2013
This won't help

Code:
till FNR==NR of file_1.dat I want to print file_1.txt selected column from row 1

if I had few files I would have tried something like this ---> not working properly

Code:
i=$(awk 'FNR == 1 {print $1,$3,$5,$6 }' OFS="\t" file_1.txt)

awk '{print '$i',$1,$2}' OFS="\t" file_1.dat

Here my problem is how do I put
Code:
for loop

for 2 type of file ? I can I input them in order ?

Last edited by nex_asp; 03-11-2013 at 11:51 AM..
# 6  
Old 03-11-2013
I don't see a reason for it to not work, may be I am not understanding your problem.
Can you esplaing more precisely what exactly are you looking for ?
# 7  
Old 03-11-2013
I need output of
Code:
FNR==1

Code:
paste tmp file_1.dat

Code:
12 14 99 AMC    12   35
    15   35
    25   87
    15   64

above is result of
Code:
 paste tmp filename

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Combine data out of 3 files into one new file

Hi, How can I combine the data of of three files into one new file? I try to give as much informations as possible. The three existing files are called file1 file2 and file3 the new file should named output_combined. The size of the files will be around 900 words/lines each .. but always... (5 Replies)
Discussion started by: MyMemberName
5 Replies

2. Shell Programming and Scripting

Combine data from two files base on uniq data

File 1 ID Name Po1 Po2 DD134 DD134_4A_1 NN-1 L_0_1 DD134 DD134_4B_1 NN-2 L_1_1 DD134 DD134_4C_1 NN-3 L_2_1 DD142 DD142_4A_1 NN-1 L_0_1 DD142 DD142_4B_1 NN-2 L_1_1 DD142 DD142_4C_1 NN-3 L_2_1 DD142 DD142_3A_1 NN-41 L_3_1 DD142 DD142_3A_1 NN-42 L_3_2 File 2 ( Combination of... (1 Reply)
Discussion started by: pareshkp
1 Replies

3. Shell Programming and Scripting

How to combine the data of files?

I have a main file as follows aaa 3/2 = 1.5 aba 55+6 = 61 aca 67+8 = 75 hjk 3+3 = 67 ghd 66+30 = 96 ghj 99-3 = 96 ffg 67+3 = 70 I have 4 sub files named sub1, sub2, sub3, sub4 content of sub1 aaa 23+5 = 28 hjk 45+6 = 51 ghd 40-20 = 20 ... (2 Replies)
Discussion started by: jackevan
2 Replies

4. Shell Programming and Scripting

Extract header data from one file and combine it with data from another file

Hi, Great minds, I have some files, in fact header files, of CTD profiler, I tried a lot C programming, could not get output as I was expected, because my programming skills are very poor, finally, joined unix forum with the hope that, I may get what I want, from you people, Here I have attached... (17 Replies)
Discussion started by: nex_asp
17 Replies

5. Shell Programming and Scripting

How to combine print and printf on awk

# cat t.txt 2,3,4,5,A,2012-01-01 00:00:28 2,6,4,5,A,2012-01-02 00:00:28 2,7,4,5,A,2012-01-02 02:00:28 # awk -F"," '{OFS=",";print $2,"";printf("%s", strftime("%m%d%y",$6));printf("%s", strftime("%H%M%S \n",$6));print ("",$1)}' t.txt 3, 010170073332 ,2 6, 010170073332 ,2 7,... (3 Replies)
Discussion started by: before4
3 Replies

6. Shell Programming and Scripting

Compare a file with all others then print off data

my script so far nawk -F, 'NR==FNR{a++;next} a{b++} END{for(i in b){if(b-1){print i";\t\t"b}else{print "NEW:"i";\t\t1"} } }' OFS=, 20111228.csv *.csv | sort NE:221478,SHELF:13,SLOT:4; 2 NE:221726,SHELF:8,SLOT:1; 2 NE:222318,SHELF:14,SLOT:1; 9... (20 Replies)
Discussion started by: llcooljatt
20 Replies

7. Shell Programming and Scripting

get data from files combine them to a file

hi people; this is my file1.txt:192.168.1.1 192.168.1.2 192.168.1.3 192.168.1.4 ... this is my file2.txt:portnames usernames maxusercap ... i want to write to file3.txt:l ./getports 192.168.1.1 'get all;l+;get . portnames;l-' l ./getports 192.168.1.1 'get all;l+;get . usernames;l-'... (4 Replies)
Discussion started by: gc_sw
4 Replies

8. Shell Programming and Scripting

Compare and print out data only appear in file 1 problem

Below is the data content of file_1 and file_2: file_1 >sample_1 FKGJGPOPOPOQA ASDADWEEWERE ASDAWEWQWRW ASDASDASDASDD file_2 >sample_1 DRTOWPFPOPOQA ASDADWEEASDF ASDADRTYWRW ASDASDASDASDD I got try the following perl script. Unfortunately, it can't give my desired output result... (7 Replies)
Discussion started by: patrick87
7 Replies

9. UNIX for Advanced & Expert Users

How to print data between 2 lines in a file

i want to print the data between two line numbers in file to another file. which command should i use i tried sed command . i am storing the line numbers in two variables say L1,L2. but $L1 and $L2 are not working in sed command. is there any other command to do this reply soon (5 Replies)
Discussion started by: kamesh83
5 Replies

10. Shell Programming and Scripting

print out result from data file

i got a data file which contains all the pid,ppid,user,command,pcpu,start_time,status. I wanted to display out the pcpu which is greater than 0. i uses awk'{if($5 > 0){print}}' filename.txt but is printing out result which not i wanted. Is there any way which i can print out those pcpu which is... (8 Replies)
Discussion started by: thms_sum
8 Replies
Login or Register to Ask a Question