Merging data horizontally with newlines in files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Merging data horizontally with newlines in files
# 1  
Old 01-03-2014
Merging data horizontally with newlines in files

Hi Everyone,

I have two files file1 and file2 with these contents

Code:
 
cat file1
AAAAA                   01/03/2014 04:01:23
BBBB                    01/03/2014 03:03:34

CCCcc                   01/03/2014 03:03:34

cat file2
1 RED
1 HHHH
1 TTTT
1 BBBBB

I tried the below command but format is not corret

Code:
 
paste file1 file2
AAAAA                   01/03/2014 04:01:23     1 RED
BBBB                    01/03/2014 03:03:34     1 HHHH
        1 TTTT
        1 BBBBB
CCCcc                   01/03/2014 03:03:34

Expected Output:
Code:
AAAAA                   01/03/2014 04:01:23     1 RED
BBBB                    01/03/2014 03:03:34     1 HHHH
             1 TTTT
             1 BBBBB
CCCcc                   01/03/2014 03:03:34


Request to let me know if you have any ideas to implement this either by using awk ??

Last edited by bartus11; 01-03-2014 at 08:10 AM.. Reason: Please use code tags
# 2  
Old 01-03-2014
Code:
paste file1 file2 | sed 's/^\s\+//g'

# 3  
Old 01-03-2014
Aditya_001,
With the input you showed us, I get the output:
Code:
AAAAA                   01/03/2014 04:01:23     1 RED
BBBB                    01/03/2014 03:03:34     1 HHHH
        1 TTTT
CCCcc                   01/03/2014 03:03:34     1 BBBBB

when I use paste, not:
Code:
AAAAA                   01/03/2014 04:01:23     1 RED
BBBB                    01/03/2014 03:03:34     1 HHHH
        1 TTTT
        1 BBBBB
CCCcc                   01/03/2014 03:03:34

We can't tell whether file1 had tab separated fields or space separated fields (since copying and pasting usually converts tabs to spaces). The default separator in paste is a single tab character and that matches the spacing shown, but it looks like you want 12 spaces or a tab and four spaces.

But more importantly, why shouldn't the 4th lines from each input file be pasted together in your output? Please clearly explain the criteria used to determine which lines should be pasted together and what separator you want between data from file1 and data from file2 in your output.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding files with newlines in filename

I want to use grep to find files that have newlines in the filename. For example, I have a directory where I create three files: $ touch file1 $ touch "file 2" $ touch "file > with > newlines" $ find . ./file 2 ./file1 ./file?with?newlinesI now want to pipe the find output into grep and... (4 Replies)
Discussion started by: Ralph
4 Replies

2. Shell Programming and Scripting

Converting space to newlines and renaming files

Hi All, I have this code which has two problems: find . -name '*.fil' | xargs while read page do cat $page | awk '{for(i=1;i<=NF;i++) print $i}' $page>$page.txt done find . -name '*.fil.txt' | xargs rename '.fil.txt' .fil 1. I am running this code in a directory consisting of large... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

3. Shell Programming and Scripting

Merging data from 2 files of different lengths?

Hi all, Sorry if someone has answered something like this already, but I have a problem. I am not brilliant with "awk" but think it should be the command to use to get what I am after. I have 2 files: job-file (several hundred lines like): 1018003,LONG MU WAN,1113S 1018004,LONG MU... (4 Replies)
Discussion started by: sgb2301
4 Replies

4. Shell Programming and Scripting

writing the content of two files to a single file horizontally

Hi all, assume that i am having two files file.1 and file.2 these are the contents of file.1 these are the contents of file.2 i want these two contents to be written in another single file like this. can you please post your suggestions. Thanks in advance, ... (3 Replies)
Discussion started by: anishkumarv
3 Replies

5. Shell Programming and Scripting

formatting and merging 2 data files

Hi, I have 2 files that I got as an output from another program. They are : File 1 ((((((CtBJa:197.0,CtBTz:197.0):85.0,CtAHr:197.0):116.0,CtDUw:197.0):176.0,CtSwe:197.0):110.0, (CtL2b:197.0,Ct4Bu:197.0):196.0):197.0,CmuNg:197.0);... (5 Replies)
Discussion started by: Lucky Ali
5 Replies

6. Shell Programming and Scripting

Append the output data horizontally

Hi experts i have a simple script that fetches the count from different servers and inserts ahead of server name like below servera,1 serverb,25 serverc,35 what i want to do is now when i run this script next day i want that output to be next to the earlier one like below and if possible... (5 Replies)
Discussion started by: raj2989
5 Replies

7. Shell Programming and Scripting

merge two files horizontally

Hi all, I have two files -- one with 1024 lines and another with 2048 lines. I want to merge them to create another file in such way that it takes 2 lines from file with 1024 lines and 4 from 2048 lines. I wrote a sample script and curious to see if there is a better way; i am sure there is,... (4 Replies)
Discussion started by: jakSun8
4 Replies

8. HP-UX

Combining files horizontally

I have 2 files, 1.txt and 2.txt which have the following format: 1.txt :451:1 :451:0 :451:1 and so on.. 2.txt :108:13897187 :108:90890789 :108:76476386 and so on.. I want to combine the files horizontally, I tried paste 1.txt 2.txt as well as cat but both of them are giving me... (3 Replies)
Discussion started by: anshuljain
3 Replies

9. Shell Programming and Scripting

Merging data

Hi, I have the following problem: Input: "num1","num2","num3",num4,num5,"num6" required output: "num1num2","num3",num4,num5,"num6" I need to join field 1 and field 2 together but I always end up getting: "num1""num2","num3",num4,num5,"num6" Note that not all fields have " at both... (8 Replies)
Discussion started by: ReV
8 Replies

10. UNIX for Advanced & Expert Users

Merging Two File Horizontally

I am trying to merge two large file horizontally using paste command. Every thing is working fine except for time. Its taking lot of time. Is there any effiecient way of doing the same thing or is there anyway by which I can improve its perfomance programatically? Thanks, Yeheya (1 Reply)
Discussion started by: yeheyaansari
1 Replies
Login or Register to Ask a Question