Double forloop?

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Double forloop?
# 1  
Old 01-20-2015
Double forloop?

how do I do a double forloop or any other loops like this

reads txt file a
read first line

read txt file b
read first line

then run command 

lun map $line1_from_txtA $line1_from_txtB


Last edited by Don Cragun; 01-20-2015 at 03:30 AM.. Reason: Add CODE tags.
# 2  
Old 01-20-2015
Please use code tags for all code.
What have you tried so far?
# 3  
Old 01-20-2015
That depends on how you want the files' lines combined; every single file1 line with all file2 lines, file1 line1 with file2 line1, other?
# 4  
Old 01-20-2015
A question for clarification.

Assuming you have two files with 5 records, do you want output that is the first or second?:-
1 1
1 2
1 3
1 4
1 5
2 1
2 2
2 3

1 1 
2 2
3 3
4 4
5 5

# 5  
Old 01-20-2015
it will be file1 line1 to file2 line1

while loop or for loop?

I dont know how to approach it
# 6  
Old 01-20-2015
# Open file into FD 5
exec 5<file1
# Open file into FD 6
exec 6<file2

# Read from both files
while read -r LINE1 <&5 && read -r LINE2 <&6
        echo "Line1 is $LINE1"
        echo "Line2 is $LINE2"

# Close FD 5
exec 5<&-
# Close FD 6
exec 6<&-

This can be further improved if we knew what you were reading -- if you had tokens you needed split etc.

Last edited by Corona688; 01-21-2015 at 01:16 PM.. Reason: Fixed typo, LINE / LINE1
These 3 Users Gave Thanks to Corona688 For This Post:
# 7  
Old 01-20-2015
Where could i read into this FD?
Because man [fF][dD] gives me just the floppy-disk tool manpage, and i am very certain its not that.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Executing statements inside forloop parallely

Hi All, I have made a forloop as given below. if ]; then echo -e "serv_AAA_DS.ldif file created and will be splitted into 8 smaller files for ldapadd \n" sh ./ for (( w=1; w <= 8; ++w )) do nohup ldapadd -x -c -h PL0 -p 389 -D "$LDAP_USER" -w... (8 Replies)
Discussion started by: Kamesh G
8 Replies

2. Shell Programming and Scripting

Replace Double quotes within double quotes in a column with space while loading a CSV file

Hi All, I'm unable to load the data using sql loader where there are double quotes within the double quotes As these are optionally enclosed by double quotes. Sample Data : "221100",138.00,"D","0019/1477","44012075","49938","49938/15043000","Television - 22" Refurbished - Airwave","Supply... (6 Replies)
Discussion started by: mlavanya
6 Replies

3. Shell Programming and Scripting

Replacing Double Quote in Double Quote incsv file

Hi All , We have source data file as csv file and since data could contain commas ,each attribute is quoted into double quotes.However problem is that some of the attributa data also contain double quotes which is converted to double double quote while creating csv file XLs data : ... (2 Replies)
Discussion started by: Shalini Badal
2 Replies

4. Shell Programming and Scripting

What does a double $ represents?

Hi Team, I have the following statement in my script "chgrp dw $$DSSDATW5/W5DW_RUNNING.out" Which throws the error "chgrp: 50528606DSSDATW5/W5DW_RUNNING.out: No such file or directory" Can you please let me know what does this $$ refers to (2 Replies)
Discussion started by: Agent154
2 Replies

5. Shell Programming and Scripting

Replace double quotes with a single quote within a double quoted string

Hi Froum. I have tried in vain to find a solution for this problem - I'm trying to replace any double quotes within a quoted string with a single quote, leaving everything else as is. I have the following data: Before: ... (32 Replies)
Discussion started by: pchang
32 Replies

6. UNIX for Dummies Questions & Answers

double while

file1 contents: jandoe1 johndoe1 file2 contents: jandoe johndoe my output file names file3, and has contents as: This is jandoe1 my script: cat file1 | while read line1 cat file2 | while read line2 do do sed -e 's/${line1}/${line2}/g' file3 > file3 done done (5 Replies)
Discussion started by: lawsongeek
5 Replies

7. Shell Programming and Scripting

Replace double double quotes using AWK/SED

Hi, I have data as "01/22/97-"aaaaaaaaaaaaaaaaa""aaa""aabbbbbbbbcccccc""zbcd""dddddddddeeeeeeeeefffffff" I want to remove only the Consequitive double quotes and not the one which occurs single. My O/P must be ... (2 Replies)
Discussion started by: Bhuvaneswari
2 Replies

8. Shell Programming and Scripting

double-quote inside double-quote

hey all, i made a simple .sh like this: echo "<style media="screen" type="text/css">@import url("main.css");</style>" but the output is: <style media=screen type=text/css>@import url(main.css);</style> i want to keep double-quotes, can anyone help me? thanks (3 Replies)
Discussion started by: indraf
3 Replies

9. Programming

double pow (double x, double y) -- problems

This is the code and I'm wondering why line 14: a = ... and line 16: b = ... is wrong. This is the first time I've tried to use this. Please help me. #include <stdio.h> #include <math.h> // The link and how the double pow is used. // // //... (2 Replies)
Discussion started by: pwanda
2 Replies

10. Shell Programming and Scripting

double substitution

Hello, I would like to dual subtitutes variables. I tried $serv="combo" combo_TYPE="mop" TYPENAME="$serv_TYPE" Now, I'd like to get "mop" from TYPENAME echo "${${TYPENAME}}" I have a bad substitution error :) (1 Reply)
Discussion started by: pppswing
1 Replies
Login or Register to Ask a Question

Featured Tech Videos