Using GAWK to combine files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using GAWK to combine files
# 1  
Old 11-13-2009
Using GAWK to combine files

Hello All,

I have a folder containing few files. Each & every file contain only 1 column.

I want to combine only column of all the files through GAWK, separate them by a delimiter and store it to a new file.

So basically using GAWK, I want to combine '$1' of all files, separate them by a delimiter and save it in a file:
i.e. '$1:$1:$1:$1:$1.....'
# 2  
Old 11-13-2009
This should work:
Code:
{ tr '\n' ':'  * ; echo ; } >../output

# 3  
Old 11-13-2009
I'll suggest paste - merge corresponding or subsequent lines of files
Code:
paste -d\: * > newfile

# 4  
Old 11-13-2009
tr is throwing an error:
Quote:
tr: extra operand
And Paste is using the new line characters of the original rows. So rows are not appearing on single line. I would just like to remove new line characters of all the rows of all the columns except the column of last file.
# 5  
Old 11-13-2009
Quote:
Originally Posted by paragkalra
Hello All,

I have a folder containing few files. Each & every file contain only 1 column.

I want to combine only column of all the files through GAWK, separate them by a delimiter and store it to a new file.

So basically using GAWK, I want to combine '$1' of all files, separate them by a delimiter and save it in a file:
i.e. '$1:$1:$1:$1:$1.....'
Code:
awk '{printf("%s%s", NR==1?"":":", $0)}END{print ""}' * > newfile

# 6  
Old 11-13-2009
Quote:
Originally Posted by paragkalra
And Paste is using the new line characters of the original rows. So rows are not appearing on single line.
Hmm, here is my test
Code:
# ls
file1   file2   file3   file4   file5   file6   file7   file8   file9
# cat *
1
2
3
4
5
6
7
8
9
# paste -d\: *
1:2:3:4:5:6:7:8:9

Can you post a data sample.
# 7  
Old 11-14-2009
I think I missed out one information....

Although all the files have 1 column but that 1 column may have multiple rows but number of rows in all the rows will remain same...

Last edited by paragkalra; 11-14-2009 at 12:59 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Automate splitting of files , scp files as each split completes and combine files on target server

i use the split command to split a one terabyte backup file into 10 chunks of 100 GB each. The files are split one after the other. While the files is being split, I will like to scp the files one after the other as soon as the previous one completes, from server A to Server B. Then on server B ,... (2 Replies)
Discussion started by: malaika
2 Replies

2. Windows & DOS: Issues & Discussions

gawk: Merge N files into one

hi all! i'm an awk newbie and have been trying in vain to merge N files together. ie. file1.txt: a b c 1 1 1 2 2 2 3 3 3 4 4 4 file2.txt: a b c 5 5 5 6 6 6 7 7 7 8 8 8 (13 Replies)
Discussion started by: sameeribraimo
13 Replies

3. Shell Programming and Scripting

combine two files...

Hi, i have two files. i want to combine records from these two files in below manner :- first line from first file(1st line) 2nd line from 2nd file(1st line) 3rd line from 1st file(2nd line) 4th line from 2nd file(2nd line) so on.... (1 Reply)
Discussion started by: deepakiniimt
1 Replies

4. Shell Programming and Scripting

Reading in all files from parent directory (GAWK)

Hi all, I'm very, very new to scripting (let alone SHELL) and was wondering if anyone could help me out as I seem to be in a spot of bother. I collect data (.dat files) which are automatically seperated into several sub directories, so the file paths I'm reading in at the moment would be... (11 Replies)
Discussion started by: gd9629
11 Replies

5. Shell Programming and Scripting

combine multiple files by column into one files already sorted!

I have multiple files; each file contains a certain data in a column view simply i want to combine all those files into one file in columns example file1: a b c d file 2: 1 2 3 4 file 3: G (4 Replies)
Discussion started by: ahmedamro
4 Replies

6. Shell Programming and Scripting

gawk - reading two files & re arrange the columns

Hi, I am trying to read 2 files and writing to the 3rd file if I find the same elements in 2 files. my first file is 1 0 kb12124819 766409 1.586e-01 1 0 kb17160939 773886 8.674e-01 1 0 kb4475691 836671 8.142e-01 1 0 ... (2 Replies)
Discussion started by: ezhil01
2 Replies

7. Shell Programming and Scripting

Combine files with same name

I need a script that combines files with the same name. These files are on a windows directory but the PC has Cygwin so i have a limited unix command set. What I've got; WebData_9_2007-09-20.txt WebData_9_2007-09-20.txt WebData_9_2007-09-21.txt WebData_9_2007-09-20.txt... (4 Replies)
Discussion started by: jmwhitford
4 Replies

8. Shell Programming and Scripting

combine two files

I have two files: file1 and file2 the content of files1 is: 13 22 333 42 56 55 ... the content of file2 is: aa dd cc ee ff gg ... (1 Reply)
Discussion started by: fredao1
1 Replies

9. Shell Programming and Scripting

How to combine 2 files

hi all i have 2 files f1 and f2 i have to combine these 2 files and make a new file f3 when i use paste f1 f2 >f3 its pasting vertically but i want to paste horizontally How to do .. pls let me know (2 Replies)
Discussion started by: ravi.sadani19
2 Replies

10. UNIX for Dummies Questions & Answers

how to combine two files

i need to combine two file. These two files have the same line number, and i need to combine each corresponding line. I tried the paste, but i need coma as the delimeter. are there anyway to do it? thanks. (4 Replies)
Discussion started by: tao
4 Replies
Login or Register to Ask a Question