Want to read data from a file name.txt and search it in another file and then matching...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Want to read data from a file name.txt and search it in another file and then matching...
# 8  
Old 02-01-2012
You can check this code Smilie
Code:
 
#!/bin/bash

while read MSISDN; do
        awk -F'|' '/^'"$MSISDN"'/ {print $0}' source.txt >> output

done < msidsn.txt

This User Gave Thanks to knight_eon For This Post:
# 9  
Old 02-01-2012
Quote:
Originally Posted by knight_eon
You can check this code Smilie
Code:
 
#!/bin/bash

while read MSISDN; do
        awk -F'|' '/^'"$MSISDN"'/ {print $0}' source.txt >> output

done < msidsn.txt

Thanks a tonn SmilieSmilie
# 10  
Old 02-01-2012
cat name.txt | while read line
do
grep -e $line source.txt >> resultfile.txt
done

Output-:
msisdn | imsi | name | subscription | product | date | recharge type
09311424354 | 09488439820 | ekta | yes | VAS | 2012-12-07 | IVR
09128734473 | 83974738734 | priya | no | Non VAS | 2011-08-11 | SMS

Hope this might help you
This User Gave Thanks to parthmittal2007 For This Post:
# 11  
Old 02-01-2012
Quote:
Originally Posted by parthmittal2007
cat name.txt | while read line
do
grep -e $line source.txt >> resultfile.txt
done

Output-:
msisdn | imsi | name | subscription | product | date | recharge type
09311424354 | 09488439820 | ekta | yes | VAS | 2012-12-07 | IVR
09128734473 | 83974738734 | priya | no | Non VAS | 2011-08-11 | SMS

Hope this might help you
Thanks a tonn buddy..

---------- Post updated at 07:59 AM ---------- Previous update was at 07:58 AM ----------

Quote:
Originally Posted by knight_eon
You can check this code Smilie
Code:
 
#!/bin/bash

while read MSISDN; do
        awk -F'|' '/^'"$MSISDN"'/ {print $0}' source.txt >> output

done < msidsn.txt

it works with other unix systems but i am using below one :
Linux magnolia 2.6.16.60-0.21-smp #1 SMP Tue May 6 12:41:02 UTC 2008 x86_64 x86_64 x86_64 GNU/Linux

It is showing incorrect output with the awk filter..is it that awk doesnt work fine with the above system???
# 12  
Old 02-02-2012
Quote:
Originally Posted by ektubbe

it works with other unix systems but i am using below one :
Linux magnolia 2.6.16.60-0.21-smp #1 SMP Tue May 6 12:41:02 UTC 2008 x86_64 x86_64 x86_64 GNU/Linux

It is showing incorrect output with the awk filter..is it that awk doesnt work fine with the above system???
If you can please post the output of the above script here?

---------- Post updated at 11:15 AM ---------- Previous update was at 11:01 AM ----------

Quote:
Originally Posted by parthmittal2007
Code:
cat name.txt | while read line
do
grep -e $line source.txt >> resultfile.txt
done



Output-:
msisdn | imsi | name | subscription | product | date | recharge type
09311424354 | 09488439820 | ekta | yes | VAS | 2012-12-07 | IVR
09128734473 | 83974738734 | priya | no | Non VAS | 2011-08-11 | SMS

Hope this might help you
What if the source.txt contains for eg. 09311424354 in imsi field as well? or somewhere else?

Rather this will be more robust and will eliminate possibility of above scene:

Code:
cat name.txt | while read line
do
grep -e "^${line}" source.txt >> resultfile.txt
done



Including ^ (carat) above will ensure that the pattern is searched at the beginning of the line only, not in between Smilie
# 13  
Old 02-02-2012
Bug

Quote:
Originally Posted by knight_eon
If you can please post the output of the above script here?

---------- Post updated at 11:15 AM ---------- Previous update was at 11:01 AM ----------



What if the source.txt contains for eg. 09311424354 in imsi field as well? or somewhere else?

Rather this will be more robust and will eliminate possibility of above scene:

Code:
cat name.txt | while read line
do
grep -e "^${line}" source.txt >> resultfile.txt
done

Including ^ (carat) above will ensure that the pattern is searched at the beginning of the line only, not in between Smilie
helloo..
the source file is quite big.....say 800000 records and name.txt is having 8000 records so i m not sure whether grep will not take that much of time...Smilie
# 14  
Old 02-02-2012
Quote:
Originally Posted by ektubbe
helloo..
the source file is quite big.....say 800000 records and name.txt is having 8000 records so i m not sure whether grep will not take that much of time...Smilie
And what output you are getting when you run this command:

Code:
#!/bin/bash

while read MSISDN; do
        awk -F'|' '/^'"$MSISDN"'/ {print $0}' source.txt >> output

done < name.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to get the shell script to read the .txt file as an input/data?

i have written my shell script in notepad however i am struggling to pass the data file to be read to the script the data file is of .txt format. My target is to run the shell script from the terminal and pass 3 arguments e.g. polg@DESKTOP-BVPDC5C:~/CS1420/coursework$ bash valsplit.sh input.txt... (11 Replies)
Discussion started by: Gurdza32
11 Replies

2. Shell Programming and Scripting

Read in search strings from text file, search for string in second text file and output to CSV

Hi guys, I have a text file named file1.txt that is formatted like this: 001 , ID , 20000 002 , Name , Brandon 003 , Phone_Number , 616-234-1999 004 , SSNumber , 234-23-234 005 , Model , Toyota 007 , Engine ,V8 008 , GPS , OFF and I have file2.txt formatted like this: ... (2 Replies)
Discussion started by: An0mander
2 Replies

3. Shell Programming and Scripting

create txt file form data file

File A.txt LL07 LL07_B_1 20 LL85 LL85_A_1 40 LL85 LL85_B_1 40 LL85 LL85_C_1 30 LL37 LL37_A_1 60 LL37 LL37_B_1 20 LL37 LL37_C_1 50 I want cretae diffrent tex file base of above file Should be threee text file LL07.txt LL85.txt LL37.txt Eaach text file have below data... (2 Replies)
Discussion started by: asavaliya
2 Replies

4. Shell Programming and Scripting

create txt file form data file and add some line on it

Hi Guys, I have file A.txt File A Data AK1521 AK2536 AK3164 I want create text file of all data above and write some data on each file. want Output on below folder /home/kka/out AK1521.txt Hi Welocme (3 Replies)
Discussion started by: asavaliya
3 Replies

5. Shell Programming and Scripting

Get Data From CSV File and put into a txt file

Hi Guys, File A I have File A as CSV Format.... No R SS MK Par value S AL A1 PKL123 Lo12 1 S AL A2 PKl123 Lo34 22 S AL A3 PkLK234 Lo67 -34 S AL A4 PkLK235 Lo09 120 S AL A5 PkLK236 Lo76 19 S AL A6 PkLK237 Lo44 -17 S AL A7 PkLK238 Lo90 2 S AL A8 PkLK239 Lo34 -9 I want file B like... (4 Replies)
Discussion started by: asavaliya
4 Replies

6. Shell Programming and Scripting

shellscript to read data from txt file and import to oracle db

Hi all, Help needed urgently. I am currently writing a shellscript to read data/record from a flat file (.txt) file, and import/upload the data to oracle database. The script is working fine, but it takes too long time (for 18000 records, it takes around 90 mins). I guess it takes so long... (1 Reply)
Discussion started by: robot_mas
1 Replies

7. Shell Programming and Scripting

Script to read file and extract data by matching pattern

Hello, I have a file ( say file1) which has lines like below. xxxx:xxxx,yyyy,1234,efgh zzzz:zzzz,kkkk,pppp,1234,xxxx,uuuu,oooo dddd:dddd here the word before ":" ( ie: xxxx) is the file name and the string after : are also file names, but each file name separated by "," In case of... (20 Replies)
Discussion started by: pradeepmacha
20 Replies

8. UNIX for Dummies Questions & Answers

can't read a .txt file

Hello, I have a set of .txt files I cannot read. This is a part of what I see. Is there a way to view these files? _MO<P.6D@K;WU<B$X-;)SIV/ROO!UL+1P=VTT-?,SLC`MI/6QMS#UYGGT\+)C=#\UIO`TL/0]=#/T) it's about 3 pages. Thanks for your help. Joe (3 Replies)
Discussion started by: rcracerjoe
3 Replies

9. Shell Programming and Scripting

unix script to takes the old data from a TXT file and compress them into new file

Hi, I am looking for the unix script which can takes the 2 month old data from a TXT file (there is one txt file in whiche messages are appended on daily basis) and compress them into new file.Please halp me out. (2 Replies)
Discussion started by: vpandey
2 Replies

10. UNIX for Dummies Questions & Answers

How to read last line of a txt file?

I need to read the last file for a particular day, such as, "Jun 13" because the CSV file is cumulative for the entire day, so I don't want all the previous files, I just want the last file, for that day. I ran an 'ls -al | grep "June 13" > myLs.txt' (simplified) to list all files from that day.... (2 Replies)
Discussion started by: yongho
2 Replies
Login or Register to Ask a Question