Put the lines from file A to end of lines in file B


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Put the lines from file A to end of lines in file B
# 1  
Old 09-10-2013
Put the lines from file A to end of lines in file B

I really can't figure this one out.

I have 2 files, one file is a list of hostnames and the other is a list of their corresponding IPs:

fileA:
Code:
example.com
another.org
thirdie.net

fileB:
Code:
1.1.1.1
2.2.2.2
3.3.3.3

I want to create a fileC that looks like:
Code:
example.com 1.1.1.1
another.org 2.2.2.2
thirdie.net 3.3.3.3

How would I achieve this? I have a huge sed command happening but I am not at work at the moment so I can't show you what I have so far. Any help would be great, thanks. fileA and fileB are generated from other scripts and will always have a matching amount of lines and corresponding to each other 1:1, so I just need to worry about putting A to the end of B

Last edited by Franklin52; 09-10-2013 at 03:01 AM.. Reason: Please use code tags
# 2  
Old 09-10-2013
I believe this is what you are wanting to do:
Code:
$ paste file1 file2 > file3

$ cat file1 file2 file3
example.com
another.org
thirdie.net
1.1.1.1
2.2.2.2
3.3.3.3
example.com     1.1.1.1
another.org     2.2.2.2
thirdie.net     3.3.3.3

# 3  
Old 09-10-2013
Quote:
Originally Posted by spacebar
I believe this is what you are wanting to do:
Code:
$ paste file1 file2 > file3

You're kidding... It's that simple.

Thanks for the help I will see how this goes

rz
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Add strings from one file at the end of specific lines in text file

Hello All, this is my first post so I don't know if I am doing this right. I would like to append entries from a series of strings (contained in a text file) consecutively at the end of specifically labeled lines in another file. As an example: - the file that contains the values to be... (3 Replies)
Discussion started by: gus74
3 Replies

2. Shell Programming and Scripting

deleting blank lines ONLY at the end of the file

Hi Guys, I have a quetion which was already discussed in the forum, but for some reason all approches suggested fail for me. I have a file which have blank lines at the body of the text as well as at the end. I need to delete ONLY blank lines at the end. Unfortunatly the approach below does not... (5 Replies)
Discussion started by: aoussenko
5 Replies

3. Shell Programming and Scripting

deleting the lines at the end of the file.

I have a text file with two coulmn first column is just used in to show the line number, these line number are not there in the real file. I want to delete the line 16(in this file) here, even tough there is no data inside it . this empty line is causing me a problem by throwing me garbage... (12 Replies)
Discussion started by: shashi792
12 Replies

4. Shell Programming and Scripting

Put lines of a file in an array with awk

Hello, Is there any way in awk to put every line of a file in an array and so we can like this print the line we want. For example, if we have this file aaa eee bbb fff ccc ggg ddd hhh So we can print to the output the 3rd line only ccc ggg If it is possible, please put the... (7 Replies)
Discussion started by: rany1
7 Replies

5. Shell Programming and Scripting

script to move two lines to the end of a file

My input file is multiline file and I am writing a script to search for a pattern and move the line with the pattern and the next line to the end of the file. Since I am trying to learn awk, I thought I would try it. My input looks like the following: D #testpoint 1 510.0 D #testpoint2 ... (5 Replies)
Discussion started by: banjo25
5 Replies

6. UNIX for Dummies Questions & Answers

need to extract few lines from a file and put it in another file

Hi all, I have a file which contains comments,dotted lines(-------),actual records etc.I need to fetch only the actual records and put into a new file neglecting/deleting other rows.I have a header record too which contains the column names for the actual records.i need to discard this too.how... (5 Replies)
Discussion started by: ganesh_248
5 Replies

7. Shell Programming and Scripting

Put two lines into one from file

Hello, I have a script that generates the following file named /tmp/rfkill: rf55 pts/13 Jul 10 06:38 (10.72.11.44) 15782 pts/13 5:07 b rf56 pts/15 Jul 10 06:53 (10.72.11.9) 18552 pts/15 0:28 b rf55 pts/39 Jul 10 09:12 (10.72.11.44) 19354 pts/39... (4 Replies)
Discussion started by: raidzero
4 Replies

8. Shell Programming and Scripting

put the contents of this file into a variable with multiple lines

I have a file that contains the following lines the brown quick fox jumped over the white laze dog 0123456789 I wanted to put the contents of this file into a variable so I used this code: VAR_LIST=`cat $2` where $2 is the file name passed as an argument to the script If I... (3 Replies)
Discussion started by: Nomaad
3 Replies

9. HP-UX

Add a column at the end of all the lines in a file

Hi Guys, :D I am very much new to UNIX. I dont have much basics of coding in UNIX, so please help me out of thi ssituation. I have a file say for ex: ABC.dtd and it contains "|" delimited data as test1|testing|test3|moving past1|runing|test4|going I need to add a column at the end... (6 Replies)
Discussion started by: ruthless
6 Replies

10. Shell Programming and Scripting

Blank Lines - End of file

Hi all I need to strip blank lines from the end of a file. I have searched and found topics on how to strip lines from the entirety of a file - however I need to limit this to only the last 3-4 lines. Any ideas? Thanks (4 Replies)
Discussion started by: saabir
4 Replies
Login or Register to Ask a Question