1

I have a list of contact information I need to process in .txt format seperated by , . We only want to keep SIC codes that start with 65 which is real estate.

The command should only check for the correct field for data that starts with 65.

Please keep in mind that the number wont always be 6531, it just has to start with 65 (6521 6555 6587 for example would be something we would also want to keep)

2,J,John Foraste Photography,atlanticinn@biri.com,68 Middle Hwy,Barrington,RI,2806, , ,733511,Photographic Engineering,atlanticinn.com
3,X,Xerox Corp,danielle_cook@xeroxscanners.com,10 Orms St # 420,Providence,RI,02904-7815,5594547871,4012763242,504403,Copying & Duplicating Machines & Supls,www.xerox.com
4,S,St Sahag & St Mesrob Armenian,h.ghajanian@osjl.com,70 Jefferson St,Providence,RI,02908-4923,4012722832,4012727712,866107,Churches,www.stsahmes.org
13,C,Century 21 Access America,damonray@mail.com,1025 Tiogue Ave,Coventry,RI,02816-6100,4018282100, ,6531,Real Estate, 
14,B,Baxter's Showroom,rbaxters@aol.com,Null,Warwick,RI,0,4017398222,4017397058,594409,Jewelers,baxtersjewelry.com^^majorfindings.com^^robertbaxter.com^^san
17,R,Re/Max South County,ereadey@yahoo.com,56 Wells Street,Westerly,RI,2891,4015962067, ,6531,Real Estate, 
19,L,Lyn Reale - Block Island Realty,saintwolfe@computer.org,215Chapelstreet,Block Island,RI,2807,4012534311, ,653118,Real Estate,stmichaelsbristolri.org
21,R,Re/Max South County,apage@remax.net,56 Wells Street,Westerly,RI,2891,4015962067, ,6531,Real Estate, 
22,V,Vns Home Health Svc,george@vnshomehealth.org,14 Woodruff Ave # 7,Narragansett,RI,02882-3467,4017882253,4017820500,808201,Home Health Service,

After processing the list should be

13,C,Century 21 Access America,damonray@mail.com,1025 Tiogue Ave,Coventry,RI,02816-6100,4018282100, ,6531,Real Estate, 
17,R,Re/Max South County,ereadey@yahoo.com,56 Wells Street,Westerly,RI,2891,4015962067, ,6531,Real Estate, 
19,L,Lyn Reale - Block Island Realty,saintwolfe@computer.org,215Chapelstreet,Block Island,RI,2807,4012534311, ,653118,Real Estate,stmichaelsbristolri.org
21,R,Re/Max South County,apage@remax.net,56 Wells Street,Westerly,RI,2891,4015962067, ,6531,Real Estate, 
  • Does your data have a header row? – Sobrique Aug 17 '15 at 12:27
  • No we removed it. Just text separated by , in .txt – Teddy291 Aug 17 '15 at 12:28
  • 1
    You should not post data like this publicly. I hope that this is dummy examples, but it doesn't look like it – Fiximan Aug 17 '15 at 12:33
  • 1
    Why not Lyn reale with 653118? – Stéphane Chazelas Aug 17 '15 at 12:35
  • 4
    awk -F, '$11 ~ /^65/' – Stéphane Chazelas Aug 17 '15 at 12:38
2

with awk

awk -F, '{if ( $11 ~ /^65/ ) print $0}' file

explanation: use comma as field separator -F, , check if column 11 starts (^) with 65 if ( $11 ~ /^65/ ), if so print whole line print $0

  • Thanks, could you also give me the command to do this for SIC codes starting with 65 and 64? Would I just do /^64/^65/ ? – Teddy291 Aug 17 '15 at 13:32
  • an "OR" in the regex would be |, i.e. /^65|^64/ – Fiximan Aug 17 '15 at 13:34
1

This should do it:

#!/usr/bin/env perl

use strict;
use warnings;

while ( <> ) {
    print if (split /,/)[10] =~ m/^65/;
}

Can one liner it if you like as:

perl -ne 'print if (split /,/)[10] =~ m/^65/;' yourfile
0
sed '/,65[0-9]*,Real Estate/! d' file.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.