double while


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers double while
# 1  
Old 02-29-2012
double while

file1 contents:
Code:
jandoe1
johndoe1

file2 contents:
Code:
jandoe
johndoe

my output file names file3, and has contents as:
Code:
This is jandoe1

my script:
Code:
cat file1 | while read line1
cat file2 | while read line2
do
do
   sed -e 's/${line1}/${line2}/g' file3 > file3
done
done

all said and done, my output should look like this: This is jandoe

i just don't how to use double while.

Last edited by Scott; 02-29-2012 at 03:25 PM.. Reason: Use code tags, please...
# 2  
Old 02-29-2012
Code:
exec 3<file2
while read line1; do
  while read line2 <&3; do
   sed "s/${line1}/${line2}/g" file3
  done
done < file1

Output:
Code:
This is jandoe
This is johndoe

You can't write (in the sed part) back to "file3" unless your sed supports the -i option. If it doesn't, you need to write to another (temporary) file, and then copy it over the original.
# 3  
Old 02-29-2012
worked perfectly, but i don't understand:
exec 3<file2
and done < file1

and what is
<&3

and what if file3 has contents:

This is jandoe1
This is johndoe1

my output should look like this:

This is jandoe
This is johndoe

Last edited by lawsongeek; 02-29-2012 at 05:17 PM..
# 4  
Old 02-29-2012
Quote:
Originally Posted by lawsongeek
worked perfectly, but i don't understand:
Code:
exec 3<file2

Open file2 into file descriptor 3, so you can read from file2 in the future by redirecting from fd3 like <&3

Code:
and done < file1

Feed file1 into standard input for that loop only, so read commands etc inside it read from that file.

Code:
and what is 
<&3

file descriptor 3.

Last edited by methyl; 02-29-2012 at 09:51 PM.. Reason: unravel corrupt code tags
# 5  
Old 02-29-2012
Mispost
# 6  
Old 03-01-2012
sorry about that. i will post under shell scripting and programing next one i have issue/question about script. again, sorry and thank you.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. Shell Programming and Scripting

Double Quotes with sh -c

Hi, I am using the following command to create a log file. echo "`date` Starting the workflow" >> MYLOG_`date '+%d%m%Y'`.log My application (Informatica) takes the above command and issues the following to the UNIX server. sh -c "echo "`date` Starting the workflow" >> MYLOG_`date... (1 Reply)
Discussion started by: sysdata
1 Replies

7. UNIX for Dummies Questions & Answers

Double space

Hi. this is my code: set common2 = "1 2 3 4" echo $common2 you can see that between 1 and 2 there is double space but the output is 1 2 3 4 and not 1 2 3 4 what is the problam??? (4 Replies)
Discussion started by: nirnir26
4 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. // // http://www.nextdawn.nl/c-reference/pow.php //... (2 Replies)
Discussion started by: pwanda
2 Replies

10. Shell Programming and Scripting

Double asterisks

When I go$ echo *I get a directory listing. When I go$ echo * *I get a directory listing, followed by a second identical directory listing. When I go$ echo **I only get one directory listing. What happens to the second asterisk in this case? Why doesn't it expand? I haven't been able to sleep... (2 Replies)
Discussion started by: na5m
2 Replies
Login or Register to Ask a Question