The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
reading line by line a variable pppswing Shell Programming and Scripting 4 07-02-2008 11:51 AM
reading ps command's output line by line s. murat Shell Programming and Scripting 5 05-22-2008 05:23 AM
reading text file line by line MizzGail Shell Programming and Scripting 6 04-14-2008 07:58 AM
Ksh Storing Multiple Files and reading each line in each file. developncode UNIX for Dummies Questions & Answers 1 04-08-2008 05:44 PM
reading line by line and grepping QueryMaster Shell Programming and Scripting 4 01-30-2008 05:12 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-08-2008
windows windows is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 5
Post reading from two files line by line

hi
am having two files

more file1
a
b
c
d

more file2
a
b
c
d

i need a loop to read the 1st line from file1 and 1st line from file 2 and grep them from file3. Then go read the 2nd line and go on...

i tried to do it but it was a mess.
  #2 (permalink)  
Old 08-08-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,807
I am assuming 'grep from file 3' means grep -f file3, not read a record from file three to grep file 1 and file 2 records.


Code:
paste file1.txt file2.txt | grep -f file3.txt

or the other way 'round: grep single file3 record against rec1 and rec2

Code:
cnt=$( wc -l file1.txt)
> dummy1
while [[ $cnt -gt 0 ]] 
do
     echo '|' >> dummy1
     cnt=$(( cnt - 1))
done 
cp dummy1 dummy2
paste file1.txt dummy1 file2.txt dummy2 file3.txt | \
while IFS='|' && read rec1 rec2 rec3
do
       echo "$rec1"| grep  "$rec3"
       echo "$rec2" | grep "$rec3"
done

  #3 (permalink)  
Old 08-09-2008
windows windows is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 5
Thank you jim mcnamara

it worked "somehow", but now i ve a nother problem
ive input file contains to clums a and b spreated by pipe
a | b
123|456
323|455

and
xyz contains other info about a and b

now i want to print as follows:

a | b | "info from xyz"

but "info from xyz" might be more than 1 line and i want to keep the format to 3 cloums.
how to do it?
i tried the belw script but printing was worng.


Quote:
while IFS='|' && read a b
do
c=`egrep ''$a'|'$b'' xyz.txt`
awk '{print $a":" $b":" $C}' > output.txt
echo "-----------" > output.txt
done < input.txt
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:44 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0