Pasting multiple files using awk with delimiter


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Pasting multiple files using awk with delimiter
# 1  
Old 01-17-2013
Pasting multiple files using awk with delimiter

hi,

i want to PASTE two files, with a delimiter in between, using awk and pipe the output to another file. i am able to achive the reqirement using PASTE command. but it has a limitation of length till 511 bytes.


Example:
-------
File1:
----
Code:
sam
micheal


file2:
----
Code:
bosco
jackson


Output:
--------
file3:
-----

Code:
sam~bosco
micheal~jackson


Thanks in Advance...
Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 01-17-2013 at 09:47 AM.. Reason: code tags, please!
# 2  
Old 01-17-2013
Code:
awk 'FNR==NR{a[FNR]=$0;next}{print a[FNR],$0}' OFS='~' file1 file2 > file3

This User Gave Thanks to vgersh99 For This Post:
# 3  
Old 01-17-2013
Thanks for the speedy response vgersh99

but the code gives the output
~sam
~micheal
~bosco
~jackson


but my requirement is
sam~bosco
micheal~jackson
# 4  
Old 01-17-2013
It does work fine for me!
This User Gave Thanks to PikK45 For This Post:
# 5  
Old 01-17-2013
Attached screenshot.
Pasting multiple files using awk with delimiter-file3png
# 6  
Old 01-17-2013
I am working in AIX, so it does work fine.

try
Code:
awk 'FNR==NR{a[FNR]=$0;next}{print a[FNR]"~"$0}' file1 file2 > file3

This User Gave Thanks to PikK45 For This Post:
# 7  
Old 01-17-2013
Quote:
Originally Posted by mohammedsadath
Attached screenshot.
What operating system are you using?
This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell script to Split matrix file with delimiter into multiple files

I have a large semicolon delimited file with thousands of columns and many thousands of line. It looks like: ID1;ID2;ID3;ID4;A_1;B_1;C_1;A_2;B_2;C_2;A_3;B_3;C_3 AA;ax;ay;az;01;02;03;04;05;06;07;08;09 BB;bx;by;bz;03;05;33;44;15;26;27;08;09 I want to split this table in to multiple files: ... (1 Reply)
Discussion started by: trymega
1 Replies

2. Shell Programming and Scripting

Split file into multiple files using delimiter

Hi, I have a file which has many URLs delimited by space. Now i want them to move to separate files each one holding 10 URLs per file. http://3276.e-printphoto.co.uk/guardian http://abdera.apache.org/ http://abdera.apache.org/docs/api/index.html I have used the below code to arrange... (6 Replies)
Discussion started by: vel4ever
6 Replies

3. Shell Programming and Scripting

awk, multiple files input and multiple files output

Hi! I'm new in awk and I need some help. I have a folder with a lot of files and I need that awk do something in each file and print a new file with the output. The input file name should be modified when I print the outpu files. Thanks in advance for help! :-) ciao (5 Replies)
Discussion started by: gabrysfe
5 Replies

4. Shell Programming and Scripting

help with pasting files in filesystem

quick question.. say i have few files in D or E drive.. i want to paste them in Filesystem that is /home/vivek folder... but when i try to do that it shows some error saying "There is not enough space on the destination. Try to remove files to make space." but i think its due to authorization... (3 Replies)
Discussion started by: vivek d r
3 Replies

5. Shell Programming and Scripting

awk with multiple character delimiter

Hi all, I'm trying to split fields separated by multiple characters : Here's the string : "toto"||"ta|ta"||"titi" Here's what I want : "toto"||"ta|ta" I tried several ways, but it seems that my delimiter || is not working : echo "\"toto\"||\"ta|ta\"||\"titi\"" | awk 'BEGIN... (4 Replies)
Discussion started by: popawu
4 Replies

6. Shell Programming and Scripting

pasting fields from two files into one

i have two files with contents file a 1234,abcf 2345,drft 4444,befr file b tom,3 sam,5 dog,7 i want to print first column of file b and join to file a and get output as below tom,1234,abcf sam,2345,drft dog,4444,befr (2 Replies)
Discussion started by: dealerso
2 Replies

7. Shell Programming and Scripting

pasting two files while transposing one of them

hey, I have more a structural problem. I have two input files: 1.inp: 1 2 3 a b c 2 3 4 d f g and the 2.inp 6 6 6 7 7 7 8 8 8 The goal is to get as much output files (with a name 1_2_3.dat) as lines in 1.inp are like this: 6 6 6 a 7 7 7 b 8 8 8 c (5 Replies)
Discussion started by: ergy1983
5 Replies

8. UNIX for Dummies Questions & Answers

Using AWK: Extract data from multiple files and output to multiple new files

Hi, I'd like to process multiple files. For example: file1.txt file2.txt file3.txt Each file contains several lines of data. I want to extract a piece of data and output it to a new file. file1.txt ----> newfile1.txt file2.txt ----> newfile2.txt file3.txt ----> newfile3.txt Here is... (3 Replies)
Discussion started by: Liverpaul09
3 Replies

9. UNIX for Dummies Questions & Answers

Trouble pasting multiple files together!!

Hi, I would like to paste multiple files together into one large file. I have 23 of them and I would like to link them on a common variable without writing all the file names out (like in a simple join). Each has about 28,000 columns, but only 17 rows. So the final product would be a single file... (2 Replies)
Discussion started by: etownbetty
2 Replies
Login or Register to Ask a Question