LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 06-13-2007, 07:46 AM   #1
jags.singh
LQ Newbie
 
Registered: Jun 2007
Posts: 5

Rep: Reputation: 0
Shell script: not able to find


Hi

I am not able to search lines from one file in other file

following is my code;-

#!/bin/sh

file=$1
file1=$2

cat "$file" |while read line
do
rslt="`grep -i "$line" "$file1" `"
echo "$rslt"
done




following are content of both the file

file
=====

/vob/efs/EFare/Database/Filer/AFares/afares.spawner.c@@/main/pub-int/jun1307-dev/1
/vob/efs/EFare/Database/Filer/AFares/afarespf3.filer.c@@/main/pub-int/jun1307-dev/1
/vob/efs/EFare/Database/Filer/Rules/Footnotes/foots.filer.c@@/main/pub-int/jun1307-dev/1
/vob/efs/EFare/Database/Filer/Rules/Record1/record1.filer.c@@/main/pub-int/jun1307-dev/1



file1
=====
/vob/efs/EFare/Database/Filer/AFares/afares.spawner.c@@/main/pub-int/jun1307-dev/1abdkjsd
/vob/efs/EFare/Database/Filer/AFares/afarespf3.filer.c@@/main/pub-int/jun1307-dev/1dfkdsnfck
/vob/efs/EFare/Database/Filer/Rules/Footnotes/foots.filer.c@@/main/pub-int/jun1307-dev/1lfdsfm
/vob/efs/EFare/Database/Filer/Rules/Record1/record1.filer.c@@/main/pub-int/jun1307-dev/1sdfdls


please help me using script ouput si not coming.
But when I am using simple grep command output is coming.


Please help me its urgent

jags

Last edited by jags.singh; 06-13-2007 at 07:50 AM.
 
Old 06-13-2007, 08:44 AM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,695
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
Quote:
Originally Posted by jags.singh
Hi

I am not able to search lines from one file in other file

following is my code;-

#!/bin/sh

file=$1
file1=$2

cat "$file" |while read line
do
rslt="`grep -i "$line" "$file1" `"
echo "$rslt"
done




following are content of both the file

file
=====

/vob/efs/EFare/Database/Filer/AFares/afares.spawner.c@@/main/pub-int/jun1307-dev/1
/vob/efs/EFare/Database/Filer/AFares/afarespf3.filer.c@@/main/pub-int/jun1307-dev/1
/vob/efs/EFare/Database/Filer/Rules/Footnotes/foots.filer.c@@/main/pub-int/jun1307-dev/1
/vob/efs/EFare/Database/Filer/Rules/Record1/record1.filer.c@@/main/pub-int/jun1307-dev/1



file1
=====
/vob/efs/EFare/Database/Filer/AFares/afares.spawner.c@@/main/pub-int/jun1307-dev/1abdkjsd
/vob/efs/EFare/Database/Filer/AFares/afarespf3.filer.c@@/main/pub-int/jun1307-dev/1dfkdsnfck
/vob/efs/EFare/Database/Filer/Rules/Footnotes/foots.filer.c@@/main/pub-int/jun1307-dev/1lfdsfm
/vob/efs/EFare/Database/Filer/Rules/Record1/record1.filer.c@@/main/pub-int/jun1307-dev/1sdfdls


please help me using script ouput si not coming.
But when I am using simple grep command output is coming.


Please help me its urgent

jags
it works for me. What exactly doesn't work for you? you get totally blank results?
 
Old 06-13-2007, 08:54 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
Hi,

Also work here.
Could it be that you need to use #!/bin/bash instead of #!/bin/sh? Most distro's link sh to bash, but sh can also be a rather restricted version of bash.
 
Old 06-13-2007, 11:14 PM   #4
jags.singh
LQ Newbie
 
Registered: Jun 2007
Posts: 5

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by ghostdog74
it works for me. What exactly doesn't work for you? you get totally blank results?

Yeah you are right ... I am getting totally blank result...

What are you using .... sh or bash???
 
Old 06-14-2007, 12:19 AM   #5
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,695
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
Quote:
Originally Posted by jags.singh
Yeah you are right ... I am getting totally blank result...

What are you using .... sh or bash???
i am using bash.
 
Old 06-14-2007, 02:31 AM   #6
jags.singh
LQ Newbie
 
Registered: Jun 2007
Posts: 5

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by ghostdog74
i am using bash.

No luck still I am getting balnk lines....
 
Old 06-14-2007, 03:11 AM   #7
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
Hi,

I just tested a few things and I am able to replicate your problem
Your input files are dos files and _not_ unix/linux files (\r\n vs \n line endings).

This will show if the above is the case: od -c file
If the following is present, it is a dos file: \r \n. It should be \n (no \r).

Changing these files can be done in different ways (tr, dos2unix to name just two), but you want to create unix files in the first place. You don't tell if these files are created automatically or by hand and if this is done in a linux or windows environment, so I cannot give you any specific advice.

For now: open the file(s) in vi, type :set ff=unix in command mode and safe (:wg) the files.

Hope this helps.
 
Old 06-15-2007, 04:54 AM   #8
jags.singh
LQ Newbie
 
Registered: Jun 2007
Posts: 5

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by druuna
Hi,

I just tested a few things and I am able to replicate your problem
Your input files are dos files and _not_ unix/linux files (\r\n vs \n line endings).

This will show if the above is the case: od -c file
If the following is present, it is a dos file: \r \n. It should be \n (no \r).

Changing these files can be done in different ways (tr, dos2unix to name just two), but you want to create unix files in the first place. You don't tell if these files are created automatically or by hand and if this is done in a linux or windows environment, so I cannot give you any specific advice.

For now: open the file(s) in vi, type :set ff=unix in command mode and safe (:wg) the files.

Hope this helps.

Thanks now its working...


I am a beginner and creating a shell script which should COLOR the matching lines from one file in other... but all the matched(with red color) and unmatched line should remain in that file only..

Now I am not able to find any way to color those matched lines..

Could you please help me in resolving the issue.


Thanks
 
Old 06-15-2007, 10:12 AM   #9
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
Hi,

This, creating colored output inside a file, all depends what kind of file the output is written to (plain ascii, (x)html, xml, etc). It's not always possible, this too depends on the format of the output file. There are a lot of them (Wiki Document Formats List).
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to find a pattern using shell script sharad Linux - General 1 05-23-2006 03:50 AM
Shell script to find a particular string Prasun1 Linux - General 5 08-30-2005 09:23 AM
find shell script help liren Linux - Newbie 3 05-02-2005 03:05 PM
how to find the pid of a perl script from shell script toovato Linux - General 1 12-19-2003 06:25 PM
Linux can't find a shell script?? jt1020 Linux - General 4 04-27-2003 08:27 AM


All times are GMT -5. The time now is 02:08 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration