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
Shell script to search for text in a file and copy file imeadows UNIX for Dummies Questions & Answers 9 11-12-2008 09:12 PM
shell script to search content of file with timestamps in the directory psychobeauty Shell Programming and Scripting 10 04-21-2008 05:37 AM
Shell script to search through numbers and print the output cdfd123 Shell Programming and Scripting 8 10-30-2007 04:40 PM
Shell script to return all the ID's from file based on the distribution ID search kumbhatalok UNIX for Dummies Questions & Answers 1 10-06-2006 12:53 PM
Korn Shell Script - Read File & Search On Values run_unx_novice Shell Programming and Scripting 2 06-15-2005 07:20 AM

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

Join Date: Jul 2007
Posts: 112
Post search for the contents in many file and print that file using shell script

hello
have a file1
H87I
Y788O
T347U
J23U

and
file2 J23U U887Y I99U T556U
file3 I99O J99T F557J
file4 N99I T666U R55Y
file5 H87I T347U
file6 H77U R556Y E44T
file7 Y788O K98U H8I

May be using script we can use file1 to search for all the files
and have the output
H87I file5
Y788O file7
T347U file5
J23U file2
Thanks
  #2 (permalink)  
Old 10-06-2007
devtakh devtakh is offline
Registered User
  
 

Join Date: Oct 2007
Location: Bangalore
Posts: 514
Do this..you should get what you want..


while read line
do
filefound=`grep -l $line file2 file3 file4 file5 file6 file7`
output=`echo $filefound | cut -d: -f1`
echo "$line $output"
done < file1

cheers,
Devaraj Takhellambam
  #3 (permalink)  
Old 10-07-2007
cdfd123 cdfd123 is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 112
gud job sir

Quote:
Originally Posted by devtakh View Post
Do this..you should get what you want..


while read line
do
filefound=`grep -l $line file2 file3 file4 file5 file6 file7`
output=`echo $filefound | cut -d: -f1`
echo "$line $output"
done < file1

cheers,
Devaraj Takhellambam

Thanks pretty works with 20 different files ...ha.........
  #4 (permalink)  
Old 10-07-2007
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,078
awk

Hi,
I think this one is ok.

input:
Code:
a:
H87I
Y788O
T347U
J23U

b:
file2 J23U U887Y I99U T556U
file3 I99O J99T F557J
file4 N99I T666U R55Y
file5 H87I T347U
file6 H77U R556Y E44T
file7 Y788O K98U H8I
code:
Code:
awk '
{
if (NF==1)
	a[$1]=$1
else
	for (i in a)
		if($2==a[i])
			a[i]=$1
}
END{
for (i in a)
print i " "a[i]
}' a b
output:
Code:
H87I file5
J23U file2
T347U T347U
Y788O file7
Sponsored Links
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 03:05 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