i want to grep some data from other file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting i want to grep some data from other file
# 1  
Old 02-19-2009
i want to grep some data from other file

helo all

i have 2 files. and i want to grep the contents of first file from the 2nd file. but these files are too large contaning lacks of lines .
i'm using for loop but it takes so moch times . is there any other sol.
i'm using this code
"
for var in `cat succ_migrated`
do
grep $var spiceoutdata170_HLR2_new >> output1
done "

files 1st like

404140150599149
404145000433885
404145000562292
404145001022201
404145001108578
2nd file
404140150599149F,919814152178FFFF,1,1,1,1,0,0,0,
404145000433885F,919855014052FFFF,1,1,1,1,0,0,0,
404145000562292F,919855580916FFFF,1,1,1,1,0,0,0,
# 2  
Old 02-19-2009
Hammer & Screwdriver

Hi try this...

awk 'FNR==NR {a[$0]++; next} a[$0]' file1 file2

Thanks
Sha
# 3  
Old 02-19-2009
Hi,

Try this

awk '{ if(FNR==NR) arr[substr($0,1,15)]=$0;
else if(length(arr[$0]) > 0 ) print arr[$0];
}' second_file first_file

Regards

Ranjith
# 4  
Old 02-19-2009
sir plz explain me these codes properly
i'm not able to execute these codes
# 5  
Old 02-19-2009
Above ...both the scripts do the same task that you require..
it takes array of all the data from file1 as well as from file2 and it compares
both the files - kind of loop here.
mean from first file it will keep going on one by one with comparing second file.
Hope this helps you
Thanks
Sha
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 grep/sed selected data from a command or file?

Below is the output of a DB2 command. Now I have 2 requirements... Database Partition 0 -- Database TESTDB1 -- Active Standby -- Up 213 days 02:33:07 -- Date 02/22/2016 17:04:50 HADR Information: Role State SyncMode HeartBeatsMissed LogGapRunAvg (bytes) Standby ... (2 Replies)
Discussion started by: rlokesh27
2 Replies

2. UNIX for Dummies Questions & Answers

Using grep to select data from file

Hello all, Once again I need to call upon the masters for help. I have a file called endpoint_data. IN that file I have groups of endpoints. However all I need from the file is this.... ENDPOINT NAME = SIPWOODSBC SIG PRI FQDN/IP ADDRESS/DOMAIN NAME = 10.xxx.xxx.xxx SIG SEC... (4 Replies)
Discussion started by: jay11789
4 Replies

3. Shell Programming and Scripting

Remove data from grep command using the pattern in the file

Hi, I writing a shell program to remove the data from output of the find which matches a list in a file I am using the below find command to get the list of files x=`find . -name test*.dat` the output of the find command is as follows test1.dat test2.dat test3.dat test4.dat... (4 Replies)
Discussion started by: pals70423
4 Replies

4. Shell Programming and Scripting

Extracting specific lines of data from a file and related lines of data based on a grep value range?

Hi, I have one file, say file 1, that has data like below where 19900107 is the date, 19900107 12 144 129 0.7380047 19900108 12 168 129 0.3149017 19900109 12 192 129 3.2766666E-02 ... (3 Replies)
Discussion started by: Wynner
3 Replies

5. UNIX for Dummies Questions & Answers

awk and grep to search a data file

Hi everyone, I cannot figure out how I can do a search in a file that has Names, Surnames, Addresses and telephone number of a number of people. Here is an example of the data file Daisy:Hunter:490 London Road:07313196347 Richard:Murphy:983 Main Road:07002625997 Isobel:Magnusson:133 London... (1 Reply)
Discussion started by: philipisaia
1 Replies

6. Shell Programming and Scripting

read in variable data from another file - grep

Hello! I think this should be an easy solution. I have a large file with many fields of data. The first field has a unique identifier (a subject number) for every record for a chunk of data. Something like this: There were ten experimental conditions (ec), but the ec is identified by only... (11 Replies)
Discussion started by: ccox85
11 Replies

7. Shell Programming and Scripting

Big data file - sed/grep/awk?

Morning guys. Another day another question. :rolleyes: I am knocking up a script to pull some data from a file. The problem is the file is very big (up to 1 gig in size), so this solution: for results in `grep "^\ ... works, but takes ages (we're talking minutes) to run. The data is held... (8 Replies)
Discussion started by: dlam
8 Replies

8. Shell Programming and Scripting

no data redirected to a file with top and grep - why?

HI all, I want to capture cpu data in batch mode of "top" command and redirect to a file like this: top -b > cpu.dat it works! But I want to capture only Cpu lines, so i have: top -b | grep ^Cpu >cpu.dat Then I got an empty output file. Why? Could somebody explain and help me to make it... (15 Replies)
Discussion started by: fongthai
15 Replies

9. Shell Programming and Scripting

grep data and add to file

Hey, i need to write a bash program that can run through a liste of files and then pick up the last access time and modification times and then write them to a file. If anyone has done something like this before, please help me. Thanks (5 Replies)
Discussion started by: nbananda
5 Replies

10. Shell Programming and Scripting

Pipe Data From Grep Into A File

I am somewhat of a novice at unix scripting and I need a little help. Here is what im trying to do: I am trying to figure out how to pipe the following grep results into a file. /source/programs: grep "WSBL020" W* WBMB991.cbl: COPY WSBL020. WDCB003.cbl: COPY... (4 Replies)
Discussion started by: katinicsdad
4 Replies
Login or Register to Ask a Question