Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Filter records in a huge text file from a filter text file Post 302919666 by Smiling Dragon on Friday 3rd of October 2014 01:07:24 AM
Old 10-03-2014
Code:
#!/bin/sh
while read line
do
  firstword=`echo "$line" | awk '{ print $1 }'`
  if egrep "^$firstword\$" filterfile.txt
  then
    echo "$line"
  fi
done

Depending on your OS, you might need to use grep, egrep, or grep -e.
This will be pretty slow if your filter list get's excessively long, but will scale well enough regardless of file size as it doesn't pull everything into memory.
This User Gave Thanks to Smiling Dragon For This Post:
 

10 More Discussions You Might Find Interesting

1. Windows & DOS: Issues & Discussions

Filter data from text file

Hi All We have got a text file, which has data dumped from 60 tables. From these 60 tables of data we need data from 4 tables only. I tried assigning line numbers to filter out data, but it is not working as intended. below is the sample file ----Table1----- 3,dfs,43,df 4,sd,5,edd... (18 Replies)
Discussion started by: b_sri
18 Replies

2. Shell Programming and Scripting

filter out all the records which are having space in the 8th filed of my file

I have a file which is having fileds separtaed by delimiter. Ex: C;4498;qwa;cghy;;;;40;;222122 C;4498;sample;city;;;;34 2;;222123 C;4498;qwe;xcbv;;;;34-2;;222124 C;4498;jj;sffz;;;;41;;222120 C;4498;eert;qwq;;;;34 A;;222125 C;4498;jj;szxzzd;;;;34;;222127 out of these records I... (3 Replies)
Discussion started by: indusri
3 Replies

3. Shell Programming and Scripting

Shell script to read lines in a text file and filter user data

hi all, I have this file with some user data. example: $cat myfile.txt FName|LName|Gender|Company|Branch|Bday|Salary|Age aaaa|bbbb|male|cccc|dddd|19900814|15000|20| eeee|asdg|male|gggg|ksgu|19911216||| aara|bdbm|male|kkkk|acke|19931018||23| asad|kfjg|male|kkkc|gkgg|19921213|14000|24|... (4 Replies)
Discussion started by: srimal
4 Replies

4. Shell Programming and Scripting

Filter records in a file using AWK

I want to filter records in one of my file using AWK command (or anyother command). I am using the below code awk -F@ '$1=="0003"&&"$2==20100402" print {$0}' $INPUT > $OUTPUT I want to pass the 0003 and 20100402 values through a variable. How can I do this? Any help is much... (1 Reply)
Discussion started by: gpaulose
1 Replies

5. Shell Programming and Scripting

Filter a .kml file (xml) with data set from text file

I have a .kml file. So I want filter the .kml to get only the tags that have this numeric codes that they are in a text file 11951 11952 74014 11964 11965 11969 11970 11971 11972 60149 74018 74023 86378 11976 11980 11983 11984 11987 (5 Replies)
Discussion started by: pcoj33
5 Replies

6. UNIX for Dummies Questions & Answers

Solaris - Filter columns in text file and adding new column

Hello, I am very now to this, hope you can help, I am looking into editing a file in Solaris, with dinamic collums (lenght varies) and I need 2 things to be made, the fist is to filter the first column and third column from the file bellow file.txt, and create a new file with the 2 filtered... (8 Replies)
Discussion started by: jpbastos
8 Replies

7. Shell Programming and Scripting

Filter records based on 2nd file

Hello, I want to filter records of a file if they fall in range associated with a second file. First the chr number (2nd col of 1st file and 1st col of 2nd file) needs to be matched. Then if the 3rd col of the first file falls within any of the ranges specified by the 2nd and 3rd cols , then... (4 Replies)
Discussion started by: ritakadm
4 Replies

8. Shell Programming and Scripting

Filter all the lines with minimum specified length of words of a text file

Hi Can someone tell me which script will work best (in terms of speed and simplicity to write and run) for a large text file to filter all the lines with a minimum specified length of words ? A sample script with be definitely of great help !!! Thanks in advance. :) (4 Replies)
Discussion started by: my_Perl
4 Replies

9. Shell Programming and Scripting

Shell script to filter records in a zip file that contains matching columns from another file

Not sure if this is the correct forum for this question. I have two files. file1.zip, file2 Input: file1.zip col1, col2 , col3 a , b , 0:0:0:0:0:c436:9346:d40b x, y, 0:0:0:0:0:880:39f9:c9a7 m, n , 0:0:0:0:0:80c7:9161:fe00 file2.txt col1 c4:36:93:46:d4:0b... (1 Reply)
Discussion started by: anil.v
1 Replies

10. UNIX for Beginners Questions & Answers

Filter records from a log file based on timestamp

Dear Experts, I have a log file that contains a timestamp, I would like to filter record from that file based on timestamp. For example refer below file - cat sample.txt Jan 19 20:51:48 mukul-Vostro-14-3468 systemd: pam_unix(systemd-user:session): session opened for user root by (uid=0)... (6 Replies)
Discussion started by: mukulverma2408
6 Replies
POE::Filter::RecordBlock(3pm)				User Contributed Perl Documentation			     POE::Filter::RecordBlock(3pm)

NAME
POE::Filter::RecordBlock - translate between discrete records and blocks of them SYNOPSIS
Hello, dear reader. This SYNOPSIS does not contain a fully functioning sample program because your humble documenter cannot come up with a short, reasonable use case for this module. Please contact the maintainer if this module is useful to you. Otherwise you may wake up one morning to discover that it has been deprecated. $filter = new POE::Filter::RecordBlock( BlockSize => 4 ); $arrayref_of_arrayrefs = $filter->get($arrayref_of_raw_data); $arrayref_of_raw_chunks = $filter->put($arrayref_of_arrayrefs); $arrayref_of_raw_chunks = $filter->put($single_arrayref); $arrayref_of_leftovers = $filter->get_pending; $arrayref_of_leftovers = $filter->put_pending; DESCRIPTION
On input, POE::Filter::RecordBlock translates a stream of discrete items into a "block" of them. It does this by collecting items until it has BlockSize of them, then returning the lot of them in an array reference. On output, this module flattens array references. This module may be deprecated in the future. Please contact the maintainer if this module is useful to you. PUBLIC FILTER METHODS
In addition to the usual POE::Filter methods, POE::Filter::RecordBlock supports the following. new new() takes at least one mandatory argument, BlockSize, which must be defined and greater than zero. new() also accepts a CheckPut Boolean parameter that indicates whether put() should check for the proper BlockSize before allowing data to be serialized. Using CheckPut is not recommended, as it enables a write buffer in the filter, therefore breaking put() for normal use. put_pending put_pending() returns an arrayref of any records that are waiting to be sent. It is the outbound equivalent of POE::Filter's get_pending() accessor. put_pending() is not part of the canonical POE::Filter API, so nothing will use it. It's up to applications to handle pending output, whenever it's appropriate to do so. blocksize blocksize() is an accessor/mutator for POE::Filter::RecordBlock's BlockSize value. checkput checkput() is an accessor/mutator for POE::Filter::RecordBlock's CheckPut flag. SEE ALSO
POE::Filter for more information about filters in general. POE::Filter::Stackable for more details on stacking filters. BUGS
This filter may maintain an output buffer that no other part of POE will know about. This filter implements a highly specialized and seemingly not generally useful feature. Does anyone use this filter? This filter may be deprecated if nobody speaks up. AUTHORS &; COPYRIGHTS The RecordBlock filter was contributed by Dieter Pearcey. Documentation is provided by Rocco Caputo. Please see the POE manpage for more information about authors and contributors. perl v5.14.2 2012-05-15 POE::Filter::RecordBlock(3pm)
All times are GMT -4. The time now is 05:41 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy