read the lines of multiple files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting read the lines of multiple files
# 1  
Old 07-05-2012
read the lines of multiple files

I am trying to create a script which will read 2 files and use the lines of file 1 for each line on file 2.

here's my sample code

Code:
cat $SBox |
while read line
        do
        cat $Date |
        while read line
        do $SCRIPTEXE <line from first file> $2 <line from 2nd file> 
                done
        done

is this possible in shell scripting?
i am using ksh by the way
Thanks!
# 2  
Old 07-05-2012
I would say yes but what your wrote here will be a nightmare when things go wrong:
How will you distinguish the line variable between the first and the second loop...
Code:
do $SCRIPTEXE <line from first file> $2 <line from 2nd file>

will not work as written here
What is $2?
# 3  
Old 07-05-2012
Hi

Code:
paste file1 file2 | while read line1 line2
  do
    $SCRIPTEXE $line1 $line2
  done

Guru
# 4  
Old 07-05-2012
yes that is my problem
i cannot get my script to work. i wrote it that way for you guys to understand what i am tryng to do

---------- Post updated at 01:02 AM ---------- Previous update was at 01:00 AM ----------

$2 would be a parameter to be used on the other script which i am trying to call in there
# 5  
Old 07-05-2012
Just to give an idea (no time to test... sorry...)
Code:
#cat $SBox |
while read LINE1 
do
        #cat $Date |
     while read LINE2
     do 
           $SCRIPTEXE $LINE1 $2 $LINE2 
     done <$Date
done <$SBox

# 6  
Old 07-05-2012
i mean argz

---------- Post updated at 01:17 AM ---------- Previous update was at 01:08 AM ----------

cant get it to work vbe. i also tried to use the code provided by guru but it didnt work also.
# 7  
Old 07-05-2012
Code:
paste -d, file1 file2 | while IFS=, read a b; do yourscript $a $b;done

Or choose a suitable separator instead of coma.
(You may also want to add some $a and / or $b checking enhancement).
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