LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-30-2012, 06:07 AM   #1
ektubbe
LQ Newbie
 
Registered: Jan 2012
Posts: 4

Rep: Reputation: Disabled
Smile How to search data from a source file on the basis of some other file?


Hi all,
Plz help me out with this:
I have 2 files one is a source file having large amount of data and another is a .txt file having some data,suppose file 1 and 2 both are having msisdn as a common field,now i want a shell script which can filter out the data from the source file on the basis of the data present in .txt file and save it to some other location.
Plz help me out its highly urgent..

Thanks -
Epsita..
 
Old 01-30-2012, 08:07 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599
Quote:
Originally Posted by ektubbe View Post
now i want a shell script
If you want something then you better learn to ask for it properly. If you want to learn how to write a shell script OTOH then
Code:
function help() { echo "Bash scripting guides:
http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html 
http://www.tldp.org/LDP/Bash-Beginners-Guide/html/index.html 
http://www.gnu.org/software/bash/manual/html_node/index.html
http://www.grymoire.com/Unix/Sh.html
http://www.tldp.org/LDP/abs/html/ 
http://wooledge.org/mywiki/BashFAQ?action=show&redirect=BashFaq 
http://wooledge.org/mywiki/BashPitfalls"; }

Quote:
Originally Posted by ektubbe View Post
filter out the data from the source file on the basis of the data present in .txt file and save it to some other location.
Something along the lines of 'fgrep -f ".txt file" "source file" > "some other location";', see 'man grep; man fgrep;' for more nfo.


Quote:
Originally Posted by ektubbe View Post
Plz help me out its highly urgent..
LQ is a volunteer-driven community effort.
Members answer questions in their own time.
Unless the problem affects us all (Space Above And Beyond reruns, some Frant opening The Way again or discovered Philip K. Dick novels) it is not urgent.
 
Old 01-30-2012, 09:03 AM   #3
ektubbe
LQ Newbie
 
Registered: Jan 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thanks

Quote:
Originally Posted by unSpawn View Post
If you want something then you better learn to ask for it properly. If you want to learn how to write a shell script OTOH then
Code:
function help() { echo "Bash scripting guides:
http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html 
http://www.tldp.org/LDP/Bash-Beginners-Guide/html/index.html 
http://www.gnu.org/software/bash/manual/html_node/index.html
http://www.grymoire.com/Unix/Sh.html
http://www.tldp.org/LDP/abs/html/ 
http://wooledge.org/mywiki/BashFAQ?action=show&redirect=BashFaq 
http://wooledge.org/mywiki/BashPitfalls"; }
Thanks for your prompt reply but i asked what problem I was facing basically...


Quote[Something along the lines of 'fgrep -f ".txt file" "source file" > "some other location";', see 'man grep; man fgrep;' for more nfo.]
This fgrep command I am already aware of ....



LQ is a volunteer-driven community effort.
Members answer questions in their own time.
Unless the problem affects us all (Space Above And Beyond reruns, some Frant opening The Way again or discovered Philip K. Dick novels) it is not urgent.
It might not be urgent for you but was for me,....also...I understand that it is a volunteer driven community but ultimately it din't solve my problem...so no point in boasting around for something which i already knew.. :\
 
Old 01-30-2012, 09:41 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599
Quote:
Originally Posted by ektubbe View Post
it din't solve my problem...
...and there's no way telling what it would have been since you didn't post what you did and what errors you got.
 
Old 02-01-2012, 01:10 AM   #5
ektubbe
LQ Newbie
 
Registered: Jan 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
Angry

Quote:
Originally Posted by unSpawn View Post
...and there's no way telling what it would have been since you didn't post what you did and what errors you got.
Hi thanks for all your help..
below is the raw script which i wrote on some experience but not sure about the use of awk or grep....not getting ideally as the file i need to search is quite large so i wanna check how and where grep/awk would be used...
#!/usr/dt/bin/dtksh

# Declare constants
typeset -r RESULTSFILE=results
typeset -r INFILE=name.txt
typeset -r SOURCEFILE=source

# Clear or create output file.
> $RESULTSFILE

while read line_in
do
print "Search results for [${line_in}]:" >> $RESULTSFILE
grep "$line_in" $SOURCEFILE >> $RESULTSFILE
done < $INFILE

exit 0

~Thanks
Epsita
 
Old 02-01-2012, 10:30 AM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599
Example. Say you got hold of some uncompressed CDF file (U95Agb.cdf) and you want to know which probes have certain numbers of atoms. First you create your "U95Agb.cdf.numatoms" filter file:
Code:
NumAtoms=40
NumAtoms=42
NumAtoms=43
NumAtoms=45
and then you run
Code:
fgrep U95Agb.cdf -f U95Agb.cdf.numatoms > U95Agb.cdf.result
to obtain results in output file "U95Agb.cdf.result".
Easy as that.
 
  


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 do search & replace on a text file--need to extract URLs from a sitemap file Mountain Linux - General 4 08-07-2015 10:52 AM
Reading a .CSV file and then calculating average per minute basis in shell script. krishdeeps Linux - Newbie 1 04-23-2010 04:38 PM
Grep String Search, and identify source file. carl0ski Linux - General 4 01-21-2006 08:15 AM
Mailing a file on a regular basis Sn7 Linux - Software 4 07-19-2004 08:37 AM
Find File broken, need search utility, where does WineX install, KDE file roller? Ohmn Mandriva 6 07-05-2004 10:34 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:46 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration