The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
Help with selecting specific lines in a large file tansha UNIX for Dummies Questions & Answers 2 02-06-2008 08:26 AM
Count No of Records in File without counting Header and Trailer Records guiguy Shell Programming and Scripting 2 06-07-2007 12:15 PM
Select records based on search criteria on first column shashi_kiran_v UNIX for Dummies Questions & Answers 2 12-02-2005 01:49 PM
selecting each paragraph and put it into a file...help me swamymns Shell Programming and Scripting 2 10-04-2005 11:46 AM
Archiving Files by selecting years file created dmhammond UNIX for Dummies Questions & Answers 2 06-13-2005 02: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 Rating: Thread Rating: 1 votes, 1.00 average. Display Modes
  #1 (permalink)  
Old 12-16-2004
videsh77 videsh77 is offline
Registered User
  
 

Join Date: Aug 2004
Posts: 144
Question Selecting records from file on criteria.

Can I have 2 files as in input to the awk command?

Situation is somewhat below,

File A contains number & value delimited by a space.
File B contains number as a part of a line. I am not supposed
to retrieve more than 1 number from a line.

If number from file B matches with number from file A, then I will
retrieve value part from file A. I will store this found,
number - value pair in file C.

Would it be possible with single awk command? Or is there any suggestions to implement this?
  #2 (permalink)  
Old 12-16-2004
jim mcnamara jim mcnamara is online now Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
Use paste file file2 | awk

paste creates one big line from the 'parallel' lines in the input
files

example:
Code:
file1:
dog
cat 
chicken

file2:
big
bigger


paste file1 file2
output:
dog big
cat bigger
chicken
  #3 (permalink)  
Old 12-16-2004
bhargav's Avatar
bhargav bhargav is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2004
Location: USA
Posts: 511
I do some thing like this ...

>file3
exec < file2
while read line
do
grep "$line" file1 >> file3
done

sort -u file3
  #4 (permalink)  
Old 12-17-2004
videsh77 videsh77 is offline
Registered User
  
 

Join Date: Aug 2004
Posts: 144
Bhargav

if I use exec my telnet window disappears.
None of your solutions suggested work for me.

I have to read file A, read a number
Read file B search for this number & extract description beyond it.

File A

xxxx1111yyyyy
aaaa2222bbbbb
cccc3333ddddd

File B
1111 desc1
2222 desc2

I know, awk deals with only 1 file.

Any suggestions?
  #5 (permalink)  
Old 12-17-2004
jim mcnamara jim mcnamara is online now Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
It seems to me if you gave us all of the requirements up front you would get a better answer.

What is your exact output supposed to be? just the description?
Or the common number field followed by the description?

try
Code:
man join
for your edification.

Based on your requirements so far:
Code:
awk ' { print substr($0,4,4) } ' file1 | sort -u  tmp.sed
grep -f tmp.sed file2 | awk ' {  print $2 } '
This prints descriptions for each record in file1.
  #6 (permalink)  
Old 12-17-2004
videsh77 videsh77 is offline
Registered User
  
 

Join Date: Aug 2004
Posts: 144
Talking

Jim
Thanks, Your solution helps.

Guys/Gals please suggest me good links where I can start with basics of shell scripts including awks.
  #7 (permalink)  
Old 12-17-2004
bhargav's Avatar
bhargav bhargav is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2004
Location: USA
Posts: 511
Using awk ... u were originally looking for .....


awk -v s="file2" '{
while(getline a[x++] <s ) ;
for(x in a)
{
if($0 ~ substr(a[x++],5,4))
{
print $0 ;
}
}

}' file1
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 11:22 AM.


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