awk Merging multiple files with symbol representing new file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk Merging multiple files with symbol representing new file
# 1  
Old 03-18-2013
awk Merging multiple files with symbol representing new file

I just tried following

Code:
ls *.dat|sort -t"_" -k2n,2|while read f1 && read f2; do
awk '{print}' $f1
awk FNR==1'{print $1,$2,$3,$4,$5,"*","*","*" }' OFS="\t" $f2  
awk '{print}' $f2 
done

got following result


Code:
18-Dec-1983    11:45:00    AM    18.692    84.672    0    25.4    24
18-Dec-1983    11:45:00    AM    18.692    84.672    5    25.5    24
18-Dec-1983    11:45:00    AM    18.692    84.672    10    26    24
18-Dec-1983    03:22:00    PM    18.327    84.29    *    *    *
18-Dec-1983    03:22:00    PM    18.327    84.29    0    24.5    24
18-Dec-1983    03:22:00    PM    18.327    84.29    5    24.6    24
18-Dec-1983    03:22:00    PM    18.327    84.29    10    24.8    24
18-Dec-1983    03:22:00    PM    18.327    84.29    40    27.1    24
18-Dec-1983    03:22:00    PM    18.327    84.29    45    27    24
18-Dec-1983    06:45:00    PM    18.025    83.962    0    26.4    23 -- > before this line * symbol suppose to come
18-Dec-1983    06:45:00    PM    18.025    83.962    5    26.5    23
18-Dec-1983    06:45:00    PM    18.025    83.962    10    26.5    23
18-Dec-1983    06:45:00    PM    18.025    83.962    15    26.8    23

Can anyone tell me why it's not coming and what's solution ?
# 2  
Old 03-18-2013
If a file exists but it's empty then FNR==1 in awk will not be met and nothing will print.
# 3  
Old 03-18-2013
what I will do to merge file

I need output like above, so I tried above code if I use
Code:
cat

I can't separate by * symbol
# 4  
Old 03-18-2013
try something like this:
Code:
ls *.dat|sort -t"_" -k2n,2|while read f1 && read f2; do
awk '$1=$1' OFS="\t" $f1
awk 'BEGIN {OFS="\t"; print "*", "*", "*", "*", "*", "*","*","*" } $1=$1' OFS="\t" $f2
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Merging multiple files into one

Hi guys, could you please help me with this? I have multiple files with this structure: file1 xxx1 1.0 xxx2 3.5 xxx3 2.4 xxx4 3.0 … xxx1890 5.7 file2 xxx1 8.0 xxx3 7.5 xxx4 5.5 …. (4 Replies)
Discussion started by: coppuca
4 Replies

2. Shell Programming and Scripting

Merging Multiple Columns between two files

Hello guys, I have 2 CSV files which goes like this: CSV1: Breaking.csv: UTF-8 "Name","Description","Occupation","Email" "Walter White","","Chemistry Teacher","w.w@bb.com" "Jessie Pinkman","","Junkie","j.p@bb.com" "Hank Schrader","","DEA Agent","h.s@bb.com" CSV2: Bad.csv... (7 Replies)
Discussion started by: jeffreybsu
7 Replies

3. Shell Programming and Scripting

Perl - multiple keys and merging two files

Hi, I'm not a regular coder but some times I write some basic perl script, hence Perl is bit difficult for me :). I'm merging two files a.txt and b.txt into c.txt: a.txt ------ x001;frtb70;xyz;109 x001;frvt65;sec;239 x003;wqax34;jul;659 x004;yhud43;yhn;760 b.txt ------... (8 Replies)
Discussion started by: Lokesha
8 Replies

4. Shell Programming and Scripting

Merging multiple files from multiple columns

Hi guys, I have very basic linux experience so I need some help with a problem. I have 3 files from which I want to extract columns based on common fields between them. File1: --- rs74078040 NA 51288690 T G 461652 0.99223 0.53611 3 --- rs77209296 NA 51303525 T G 461843 0.98973 0.60837 3... (10 Replies)
Discussion started by: bartman2099
10 Replies

5. Shell Programming and Scripting

Merging multiple files using lines from one file

I have been working of this script for a very long time and I have searched the internet for direction but I am stuck here. I have about 3000 files with two columns each. The length of each file is 50000. Each of these files is named this way b.4, b.5, b.6, b.7, b.8, b.9, b.10, b.11, b.12... (10 Replies)
Discussion started by: iconig
10 Replies

6. Shell Programming and Scripting

Merging information from multiple files to a single file

Hello, I am new to unix and need help with a problem. I have 2 files each containing multiple columns of information ie; File 1 : A B C D E 1 2 3 4 5 File 2 : F G 6 7 I would like to merge the information from File 2 to File 1 so that the data reads as follows; File 1: A... (4 Replies)
Discussion started by: crunchie
4 Replies

7. Shell Programming and Scripting

Merging columns from multiple files

Hello, I have a number of tab delimited data files consists of two columns. Like that: File1 800.000000 0.002744 799.000000 0.002517 798.000000 0.002836 797.000000 0.002553 FIle2 800.000000 0.000261 799.000000 0.000001 798.000000 0.000551 797.000000 0.000275 File3... (19 Replies)
Discussion started by: erden
19 Replies

8. UNIX for Advanced & Expert Users

Merging multiple .so files

Hi All, How to merge independent .so files into an executable. Thanks in Advance, Regards, Kusu (2 Replies)
Discussion started by: Kusu
2 Replies

9. Shell Programming and Scripting

Merging columns from multiple files in one file

Hi, I want to select columns from multiple files and combine them in one file. The files are simulation-data-files with 23 columns each and about 50 rows. I now use: cut -f 11 Sweep?wing-30?scale=0.?0?fan2?.txt | pr -3 | awk '{printf("\n%s\t%s\t%s",$1,$2,$3)}' > ../Data_Processed/output.txtI... (1 Reply)
Discussion started by: isgoed
1 Replies

10. Shell Programming and Scripting

merging multiple log files

Hello, I have 8 sql loader scripts which produce ".bad" file if there is any errors, how can I join the contents of these files together in one column? file 1 CA-94061-TSS Tkb Sport Shop CA-95133-V Vollyrite ... (3 Replies)
Discussion started by: jack1981
3 Replies
Login or Register to Ask a Question

Featured Tech Videos