Sponsored Content
Full Discussion: Combining files line by line
Top Forums Shell Programming and Scripting Combining files line by line Post 302773177 by ericJDS on Wednesday 27th of February 2013 12:47:01 PM
Old 02-27-2013
Combining files line by line

Hi,

I have 2 files say abc and txt,

Contents of abc
A
B
C
D
.
.
.


Contents of xyz

1
2
3
4
.
.
.

I need the output as

A 1
B 2
C 3
D 4
. .
. .


I do not know how many records would be there but both would have same number of records

I am trying to use 2 variables in for(is it possible?)

Code:
for i in file1, j in file2
do
echo $i $j
done

This gives error.. Please help.
 

10 More Discussions You Might Find Interesting

1. Red Hat

combining two/three line in to one

Hi Radoulov, I have tried the code for testing as I too required this on numbers of occasion to combining two line having length of 132 characters .I am using RedHat 9 Linux. I am using like if ( nr % 2 == o ) or if ( nr % 3 == 0 ) and fetching the data from the... (0 Replies)
Discussion started by: vakharia Mahesh
0 Replies

2. Programming

Combining multiple command line arguments

suppose the user enters: ./Myfile blah1 blah2 blah3 I want to be able to read that in as: blah1blah2blah3 IN ONE VARIABLE Obviously I can print it out in one line excluding the white space, but I'm having trouble combining argv, argv, ....., argv together! This is what I tried, but I... (3 Replies)
Discussion started by: hansel13
3 Replies

3. Shell Programming and Scripting

Line by Line combining 2 files

I am trying to take 2 files and merge them into a single file pulling one line out of each file at a time. Below is an example of what I am trying to do, thanks for any help in advance. Example of File 1: a1 b1 c1 Example of File 2: a2 b2 c2 Expected Outcome: a1 a2 b1 b2 c1 c2 (2 Replies)
Discussion started by: Takau
2 Replies

4. Shell Programming and Scripting

Combining 2 lines in a file into 1 line

Hi all, I have a file with lot of lines with repeating pattern. ( TABLE_NAME line followed by Total line). I would like combine these two lines into one line seperated by cama and create a new file. Is there a simple way to do this. Current Format ( just a sample 4 lines ) TABLE_NAME:... (10 Replies)
Discussion started by: MKNENI
10 Replies

5. Shell Programming and Scripting

how to read the contents of two files line by line and compare the line by line?

Hi All, I'm trying to figure out which are the trusted-ips and which are not using a script file.. I have a file named 'ip-list.txt' which contains some ip addresses and another file named 'trusted-ip-list.txt' which also contains some ip addresses. I want to read a line from... (4 Replies)
Discussion started by: mjavalkar
4 Replies

6. Shell Programming and Scripting

Combining lines in to one line

Hi Friends, I have a file1.txt 1001 jkilo yrhfm 200056 jhdf rjhwjkrh 3+u8jk5h3 uru ehjk 1002 jkfhk hfjkd 2748395 fdjksfh hefjkh 3hdfk ejkh kjhjke In the above if you see the firt charcter of each line mentioned in red has a pattern . I need to create another file where , the... (6 Replies)
Discussion started by: i150371485
6 Replies

7. Shell Programming and Scripting

Combining two files line by line

Hello guys, I have a problem with two text files. I want to join them line by line with a bash script if it is possible. I think an example will be much clear; FILE 1 314.01 83.826 52.43 79.544 316.36 45.283 351.15 87.503 FILE 2 140.323 84.918 130 78.256 120 77.603 118 ... (4 Replies)
Discussion started by: johankor
4 Replies

8. Shell Programming and Scripting

Combining lines into a single line

i have a file (where the column values are separated by ' and the text can be enclosed in ~) which contains data in form of 4461,2,~Basic: 2 Years/Unlimited Miles Drivetrain: Gas Engine 2 Years/Unlimited Miles Duramax Engine 3 Years/Unlimited... (2 Replies)
Discussion started by: rahulchandak
2 Replies

9. UNIX for Beginners Questions & Answers

Combining lines in one line

Hi below is the input file snippet. here i want that all the line which is coming after 1 shoud be in one line. so for exanple if after 1 there is two lines which is starting with 2 should be combine in one line. input file content 1,8091012,BATCH_1430903_01,21,T,2,808738,,,,21121:87:01,... (19 Replies)
Discussion started by: scriptor
19 Replies

10. UNIX for Beginners Questions & Answers

Get an output of lines in pattern 1st line then 10th line then 11th line then 20th line and so on.

Input file: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 (6 Replies)
Discussion started by: Sagar Singh
6 Replies
sdiff(1)						      General Commands Manual							  sdiff(1)

NAME
sdiff - side-by-side difference program SYNOPSIS
[options ...] file1 file2 DESCRIPTION
uses the output of diff(1) with the option, which ignores trailing blanks (spaces and tabs) and treats other strings of blanks as equal, to produce a side-by-side listing of two files, indicating those lines that are different. Each line of the two files is printed with a blank gutter between them if the lines are identical, a in the gutter if the line only exists in file1, a in the gutter if the line only exists in file2, and a for lines that are different. For example: abc | xyz abc abc bca < cba < dcb dcb > cde Options recognizes the following options: Use the next argument, n, as the width of the output line. The maximum value of n is 2048 (LINE_MAX). The default line length is 130 charac- ters. Only print on the left side when lines are identical. Do not print identical lines. Use the next argument, output, as the name of a third file that is created as a user-controlled merging of file1 and file2. Identical lines of file1 and file2 are copied to output. Sets of differences, as produced by diff(1), are printed; where a set of differ- ences share a common gutter character. After printing each set of differences, prompts the user with a and waits for one of the following user-typed commands: append the left column to the output file append the right column to the output file turn on silent mode; do not print identical lines turn off silent mode call the editor with the left column call the editor with the right column call the editor with the concatenation of left and right call the editor with a zero length file exit from the program On exit from the editor, the resulting file is concatenated on the end of the output file. EXAMPLES
Print a side-by-side diff of two versions of a file on a printer capable of printing 132 columns: Retrieve the most recently checked in version of a file from RCS and compare it with the version currently checked out: SEE ALSO
diff(1), ed(1). sdiff(1)
All times are GMT -4. The time now is 07:07 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy