Sponsored Content
Full Discussion: Combining multiple files
Top Forums Shell Programming and Scripting Combining multiple files Post 302784795 by Don Cragun on Saturday 23rd of March 2013 05:27:00 AM
Old 03-23-2013
You could try something like:
Code:
awk '
FNR == 1 {   
        f[++fc] = FILENAME
        if(w[fc] < length(FILENAME)) w[fc] = length(FILENAME)
}
FNR == NR {
        d[++lc] = $1
        t[lc] = $2
}
{       v[fc,$1,$2] = $3
        if(w[fc] < length($3)) w[fc] = length($3)
}
END {   printf("    Date  Time")
        for(j = 1; j <= fc; j++)
                printf("%*s%s", w[j] + 1, f[j], j == fc ? "\n" : "")
        for(i = 1; i <= lc; i++) {
                printf("%s%6s", d[i], t[i])
                for(j = 1; j <= fc; j++)
                        printf("%*d%s", w[j] + 1, v[j, d[i], t[i]],
                                j == fc ? "\n" : "")
        }
}' FILE[12]

If you are running on a Solaris/SunOS system, use /usr/xpg4/bin/awk or nawk instead of awk.

Note that this script will work for two or more files, but the 1st file given must include all date/time pairs that you want to appear in the output.

With the FILE1 and FILE2 contents specified in the 1st message in this thread, the output produced by this script is:
Code:
    Date  Time FILE1 FILE2
20130322 05:35  2219   170
20130322 05:40  1809   169
20130322 05:45  1617   172
20130322 05:50  1359   171
20130322 05:55  2233     0
20130322 06:00  1648     0
20130322 06:05  1552   176

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Combining Multiple files in one in a perl script

All, I want to combine multiple files in one file. Something like what we do on the commad line as follows -> cat file1 file2 file3 > Main_File. Can something like this be done in a perl script very efficiently? Thanks, Rahul. (1 Reply)
Discussion started by: rahulrathod
1 Replies

2. Shell Programming and Scripting

Merge text files while combining the multiple header/trailer records into one each.

Situation: Our system currently executes a job (COBOL Program) that generates an interface file to be sent to one of our vendors. Because this system processes information for over 100,000 employees/retirees (and growing), we'd like to multi-thread the job into processing-groups in order to... (4 Replies)
Discussion started by: oordonez
4 Replies

3. Shell Programming and Scripting

Combining multiple files into one with the same name/different extension

I've been trying to find information in regard to creating a script that will generate HTML files. I currently have a series of files that contain code I need to surround with a <textarea> tag for easy viewing. I have about a thousand files that contain code, one file that contains the HTML code up... (10 Replies)
Discussion started by: 12o
10 Replies

4. Shell Programming and Scripting

Combining columns from multiple files to one file

I'm trying to combine colums from multiple file to a single file but having some issues, appreciate your help. The filenames are the same except for the extension, path1.m0 --------- a b c d e f g h i path1.m1 --------- m n o p q r s t u File names are path1.m The... (3 Replies)
Discussion started by: rkmca
3 Replies

5. Shell Programming and Scripting

Combining multiple column files into one with file name as first row

Hello All, I have several column files like this $cat a_b_s1.xls 1wert 2tg 3asd 4asdf 5asdf $cat c_d_s2.xls 1wert 2tg 3asd 4asdf 5asdf desired put put $cat combined.txt s1 s2 (2 Replies)
Discussion started by: avatar_007
2 Replies

6. UNIX for Dummies Questions & Answers

Need help combining txt files w/ multiple lines into csv single cell - also need data merge

:confused:Hello -- i just joined the forums. I am a complete noob -- only about 1 week into learning how to program anything... and starting with linux. I am working in Linux terminal. I have a folder with a bunch of txt files. Each file has several lines of html code. I want to combine... (2 Replies)
Discussion started by: jetsetter
2 Replies

7. Shell Programming and Scripting

Combining columns from multiple files into one single output file

Hi, I have 3 files with one column value as shown File: a.txt ------------ Data_a1 Data_a2 File2: b.txt ------------ Data_b1 Data_b2 Data_b3 Data_b4 File3: c.txt ------------ Data_c1 Data_c2 Data_c3 Data_c4 Data_c5 (6 Replies)
Discussion started by: vfrg
6 Replies

8. Shell Programming and Scripting

Join two files combining multiple columns and produce mix and match output

I would like to join two files when two columns in each file matches with each other and then produce an output when taking multiple columns. Like I have file A 1234,ABCD,23,JOHN,NJ,USA 2345,ABCD,24,SAM,NY,USA 5678,GHIJ,24,TOM,NY,USA 5678,WXYZ,27,MAT,NJ,USA and file B ... (2 Replies)
Discussion started by: mady135
2 Replies

9. UNIX for Beginners Questions & Answers

Combining multiple files into one

Hello Everyone, I have 4 different files (one column in each) that I'm trying to combine into 1 file with four columns. Having issues trying to get the columns to format properly. I have tried the following: paste file1 file2 file3 file4 | column -s $'\t' -t > results.txt paste file1 file2... (1 Reply)
Discussion started by: malk71
1 Replies

10. Shell Programming and Scripting

Combining certain columns of multiple files into one file

Hello Unix gurus, I have a large number of files (say X) each containing two columns of data and the same number of rows. I would like to combine these files to create a unique merged file containing X columns corresponding to the second column of each file (with a bonus of having the first... (3 Replies)
Discussion started by: ksennin
3 Replies
GNUNET-NAMESTORE(1)					      General Commands Manual					       GNUNET-NAMESTORE(1)

NAME
gnunet-namestore - manipulate GNUnet zones SYNOPSIS
gnunet-namestore [options]-zZONEFILE DESCRIPTION
gnunet-namestore can be used to create and manipulate a GNS zone. OPTIONS
-a, --add Desired operation is adding a record -c FILENAME, --config=FILENAME Use the configuration file FILENAME. -d, --delete Desired operation is deleting a record -D, --display Desired operation is listing of matching records -e TIME, --expiration=TIME Specifies expiration time of record to add; format is relative time, i.e "1 h" or "7 d 30 m". Supported units are "ms", "s", "min" or "minutes", "h" (hours), "d" (days) and "a" (years). -h, --help Print short help on options. -L LOGLEVEL, --loglevel=LOGLEVEL Use LOGLEVEL for logging. Valid values are DEBUG, INFO, WARNING and ERROR. -n NAME, --name=NAME Name of the record to add/delete/display -t TYPE, --type=TYPE Type of the record to add/delete/display (i.e. "A", "AAAA", "NS", "PKEY", "MX" etc.) -v, --version Print GNUnet version number. -V VALUE, --value=VALUE Value to store or remove from the GNS zone. Specific format depends on the record type. A records expect a dotted decimal IPv4 address, AAAA records an IPv6 address, PKEY a public key in GNUnet's printable format, and CNAME and NS records should be a domain name. -z FILENAME, --zonekey=FILENAME Specifies the filename with the private key for the zone (mandatory option) BUGS
Report bugs by using Mantis <https://gnunet.org/bugs/> or by sending electronic mail to <gnunet-developers@gnu.org> SEE ALSO
gnunet-gns(1) GNUnet Mar 5, 2012 GNUNET-NAMESTORE(1)
All times are GMT -4. The time now is 07:31 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy