Small Help required for merging two files per line!!!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Small Help required for merging two files per line!!!
# 1  
Old 09-26-2011
Small Help required for merging two files per line!!!

Hi Guys,

Sorry to bother everyone again here, but I ran into a small problem that has been after me for some time now.

I have a file called file1.txt and has following content -

PHP Code:
/folder1/fold/folder   10k
/folder167fold/folder   10MB
/folder2/fold/folder   10G
etc
..
etc.. 

There is another file called file2.txt and has following content.

PHP Code:
folder1
folder5
test5
test5 
Now I am trying to merge these two into one separate file where it should look like -

PHP Code:
/folder1/fold/folder   10k folder1
/folder167fold/folder   10MB folder5
/folder2/fold/folder   10G test5
etc
..
etc.. 
So basically, I am just trying to append content of the 2nd file into file 1 at the end of each line.

I can certainly use sed 's/$/ ;FS folder1/' file 2 > output.txt however, it doesn't do the work for me since it can't add recursive content on each line of fil1.

I tried using paste -d ';' file file 2 > output.txt but it's not appending and its actually simply adding file 2 content at the end of file 1 in the final list.

Can someone please suggest me where i can append file 2 data into file1??

I am using a do -while loop as well by trying to read content of each line and then adding it to each line of file1.

Any suggestions or recommendation are of course welcome.

Thanks,
Morgan.
# 2  
Old 09-26-2011
Quote:
I tried using paste -d ';' file file 2 > output.txt but it's not appending and its actually simply adding file 2 content at the end of file 1 in the final list.
You can (and should) use "paste":
Code:
cat file1
/folder1/fold/folder   10k
/folder167fold/folder   10MB
/folder2/fold/folder   10G

cat file2
folder1
folder5
test5

paste -d';' file1 file2
/folder1/fold/folder   10k;folder1
/folder167fold/folder   10MB;folder5
/folder2/fold/folder   10G;test5

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Reading a file line by line and print required lines based on pattern

Hi All, i want to write a shell script read below file line by line and want to exclude the lines which contains empty value for MOUNTPOINT field. i am using centos 7 Operating system. want to read below file. # cat /tmp/d5 NAME="/dev/sda" TYPE="disk" SIZE="60G" OWNER="root"... (4 Replies)
Discussion started by: balu1234
4 Replies

2. Shell Programming and Scripting

Bash script to read a file from particular line till required line and process

Hi All, Am trying to write wrapper shell/bash script on a utility tool for which i need to pass 2 files as arugment to execute utility tool. Wraper script am trying is to do with above metion 2 files. utility tool accepts : a. userinfo file : which contains username b. item file : which... (2 Replies)
Discussion started by: Optimus81
2 Replies

3. Shell Programming and Scripting

Concatenate small line with next line perl script

Hello to all, I'm new to perl, I have input file that contains the string below: 315350535ff450000014534130101ff4500ff45453779ff450ff45545f01ff45ff453245341ff4500000545000This string has as line separator "ff45". So, I want to print each line but the code below is not working. perl -pe '... (2 Replies)
Discussion started by: Ophiuchus
2 Replies

4. Shell Programming and Scripting

Incorrect number of command line arguments and missing required files

I am developing a script. This script takes in one parameter which is the name of a file whose content is a list of names of some files. The script can check whether those files exist in current directory. Here is my question: If the number of provided parameters is less than one or one of the... (2 Replies)
Discussion started by: Ray Sun
2 Replies

5. Shell Programming and Scripting

Merging two files with merging line by line

Hi, I have two files and i want to merge it like, file1.txt --------- abc cde efg file2.txt ------- 111 222 333 Output file should be, -------------- abc 111 (2 Replies)
Discussion started by: rbalaj16
2 Replies

6. Shell Programming and Scripting

Small help required to create For loop

Hi, I am new to UNIX and have an issue. I need to check that whether a perticular file name exists or not. I wan to do that in loop to avoid number of IF statements. I need to check that if file10.txt exists rename that to file11.txt. if file9.txt exists rename that to file10.txt. : : if... (5 Replies)
Discussion started by: unankix
5 Replies

7. Shell Programming and Scripting

Help required on joining one line above & below to the pattern matched string line.

Hi Experts, Help needed on joining one line above & below to the pattern matched string line. The input file, required output is mentioned below Input file ABCD DEFG5 42.0.1-63.38.31 KKKK iokl IP Connection Available ABCD DEFG5 42.0.1-63.38.31 ... (7 Replies)
Discussion started by: krao
7 Replies

8. UNIX for Dummies Questions & Answers

A small script required!!

Hi All, I am using korn shell sun solaris 10 What i need is i have to grep one file and if there are any finding then i have set one flag. otherwise continue Please help Regards Arun (9 Replies)
Discussion started by: annyarun
9 Replies

9. Shell Programming and Scripting

Small shell script help required

Hi Guys, Please can some one explain me the below part of code. In this code what is the use of the line in Bold. COPY=0 if ; then echo "$CONF exists and is non-empty - backing it up" SUFFIX=`date +%Y%m%d%H%M%S` echo "cp -p $CONF $CONF.$SUFFIX" cp -p $CONF... (4 Replies)
Discussion started by: max29583
4 Replies

10. Shell Programming and Scripting

merging 2 files starting at the n'th line of the first file

Hi all, I wonder if anyone could help me: I want to merge 3 files together as shown below I've seen the post adding columns from 01-05-2002, 09:23 AM so know how to put 2 files together basically I want to take output file of 1st merge and merge it with a 3rd file but only start the... (2 Replies)
Discussion started by: olga
2 Replies
Login or Register to Ask a Question