read the lines of multiple files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting read the lines of multiple files
# 8  
Old 07-05-2012
ctsgnb i also tried your suggestion but i am getting a couple of garbage characters for $b when using the other script or shall we say "yourscript" based on your code.
# 9  
Old 07-05-2012
Your original problem statement implies and vbe's solution produces a cartesian product. The solutions from others, using paste, produce a simpler merge. Which is appropriate? You seem to be testing the solutions without realizing or commenting on this.

If there are 2 lines in file1 and 2 lines in file2, in which of the following ways should they be combined:

file1line1 file2line1
file1line2 file2line2

or

file1line1 file2line1
file1line1 file2line2
file1line2 file2line1
file1line2 file2line2

Also, to help us help you, provide better feedback. Simply saying "did not work" is not useful. Provide the exact error messages generated on your system (what os and shell are you using?). If there are no errors but the output differs from what you expect, describe how it deviates.Provide some sample input. If there are weird characters showing up, show us the code you ran, the input it used, and tell us exactly what characters they are.

Regards,
Alister

Last edited by alister; 07-05-2012 at 08:29 AM..
# 10  
Old 07-05-2012
I misunderstood your request.. I thought looking at your script and your post that you wanted the value of line of first file for each line (every - all...) lines of file 2 ) of file 2 in which case imbricated loops made sense...
I think ctsgnb's proposal is the way to go, but to help you more we would need to know the content of the files, there may be something tricky we are not aware of...
# 11  
Old 07-05-2012
Greetings alister, I did not refresh before my previous post and just saw yours now...
# 12  
Old 07-05-2012
Quote:
Originally Posted by alister
Your original problem statement implies and vbe's solution produces a cartesian product. The solutions from others, using paste, produce a simpler merge. Which is appropriate? You seem to be testing the solutions without realizing or commenting on this.

If there are 2 lines in file1 and 2 lines in file2, in which of the following ways should they be combined:

file1line1 file2line1
file1line2 file2line2

or

file1line1 file2line1
file1line1 file2line2
file1line2 file2line1
file1line2 file2line2

Also, to help us help you, provide better feedback. Simply saying "did not work" is not useful. Provide the exact error messages generated on your system (what os and shell are you using?). If there are no errors but the output differs from what you expect, describe how it deviates.Provide some sample input. If there are weird characters showing up, show us the code you ran, the input it used, and tell us exactly what characters they are.

Regards,
Alister

this is the thing that i need:

file1line1 file2line1
file1line1 file2line2
file1line2 file2line1
file1line2 file2line2

actually there are no errors. in vbe's solution, no output file was created i also tried to add a couple of echo commands but they did not show up. as for the paste command, i do not think it will work since i need every line from file 1 to join with every line from file 2. i am using ksh and the machine is HP-UX.

sample contents of FILE1

SERVERA
SERVERB

sample contents of FILE2

20120701
20120702
20120703

let me know if you need more details.
# 13  
Old 07-05-2012
Now you say there is no output file created... We cant guess what is going on, you havent answered my previous request either.
I would add now: what is your inner program doing?
How do you think you will pass $2 ? (As I said, I doubt seriously it working as written... I left it just because its a variable...)

About HP-UX and ksh:
Code:
ant:/home/vbe $ uname -sr
HP-UX B.11.11

...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Removing carriage returns from multiple lines in multiple files of different number of columns

Hello Gurus, I have a multiple pipe separated files which have records going over multiple Lines. End of line separator is \n and records going over multiple lines have <CR> as separator. below is example from one file. 1|ABC DEF|100|10 2|PQ RS T|200|20 3| UVWXYZ|300|30 4| GHIJKL|400|40... (7 Replies)
Discussion started by: dJHa
7 Replies

2. Shell Programming and Scripting

Read multiple lines at a time from file

Hello All, I have a file like below.... dn: cn=user1,ou=org,o=org cn=user1 uid=user1 cn=user2,ou=org,o=org cn=user2 uid=user2 cn=user3,ou=org,o=org cn=user3 cn=user33 uid=user3 cn=user4,ou=org,o=org cn=user4 uid=user4 (6 Replies)
Discussion started by: s_linux
6 Replies

3. Shell Programming and Scripting

Script to find & replace a multiple lines string across multiple php files and subdirectories

Hey guys. I know pratically 0 about Linux, so could anyone please give me instructions on how to accomplish this ? The distro is RedHat 4.1.2 and i need to find and replace a multiple lines string in several php files across subdirectories. So lets say im at root/dir1/dir2/ , when i execute... (12 Replies)
Discussion started by: spfc_dmt
12 Replies

4. Shell Programming and Scripting

read one line file and separate into multiple lines

I have one long line text with semicolon used as separator between values in that line. Now, I want to separate the line into multiple line right after every 29th field. example input line: ... (1 Reply)
Discussion started by: erlanq
1 Replies

5. Shell Programming and Scripting

read one line file and separate into multiple lines

I have one long line text with semicolon used as separator between values in that line. Now, I want to separate the line into multiple line right after every 29th field. example input line: ... (2 Replies)
Discussion started by: erlanq
2 Replies

6. Shell Programming and Scripting

How to read a multiple lines from a file n executing them?

Hi all, I am just trying to read the contents of a file. basically this file has a list of dat files. then i want to access these dat files n execute a script on them one by one using a loop. i hav e written like this ls -l | cut -c 58-88 > file1.txt while do arr1="$( sed -n '1p'... (7 Replies)
Discussion started by: navjyotisonu5
7 Replies

7. Shell Programming and Scripting

How to read multiple lines from Std Input into an array

Hi All, Does anyone know how to read multiple lines from standard input into an array and then iterate a loop for all the lines read. Below is an example pseudocode: I need the below filenames to be read by the script into an array or something similar: And then in the script, I... (9 Replies)
Discussion started by: bharath.gct
9 Replies

8. Shell Programming and Scripting

replace multiple lines in multiple files

i have to search a string and replace with multiple lines. example Input echo 'sample text' echo 'college days' output echo 'sample text' echo 'information on students' echo 'emp number' echo 'holidays' i have to search a word college and replace the multiple lines i have... (1 Reply)
Discussion started by: unihp1
1 Replies

9. Shell Programming and Scripting

Adding Multiple Lines to Multiple Files

Hello, I have three lines I need to add to hundreds of files. The files are all in the same format and contain the same information. I want to add the same information to the files. The new lines of information are similar. Here is an example of the three lines: line1: line2 =... (2 Replies)
Discussion started by: dayinthelife
2 Replies

10. Shell Programming and Scripting

read and match multiple lines in perl

Could any one tell me how to read and match multiple lines in perl? Did this code below still work in this situation? while (<FILE>) { if (/ /) { } } Thanks a lot! (5 Replies)
Discussion started by: zx1106
5 Replies
Login or Register to Ask a Question