Matching a string (zip code) from a list in a separate file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Matching a string (zip code) from a list in a separate file
# 8  
Old 12-11-2009
Quote:
Originally Posted by sitney
I want something that looks specifically at the zip code position chars 149-157 because there will be addresses with 5 digit numbers in them that will match against a general grep statement. As in the following examples:

Code:
MS         MARLENE       SERBRANO           14044 W 174TH ST          APT 7B                        BRONX        NY10453
MS         YANIRA        GAPONTE            34126 CRESCENT DR                                       CHICOPEE     MA01013
MS         BETZAIDA      JACOBSEN           41102 HAMILTON AVE         APT 3                         LYNN         MA01902

In your example, what could be zip codes is located at character position 114-120 and is thus 7 characters wide, not 9 characters. The are no characters at pos. 149-157. Please clarify what you mean. Also the total length of the last line is one character wider.
# 9  
Old 12-14-2009
Here is another address snippet:
Code:
           JOSE           TORRES            277 URB CRISTAL                                                           AGUADILLA                   PR006036348
MR         SCOTT          ROBBINS           Q21 CALLE LIRIO                                                           ARECIBO                     PR006123368
MR         REINALDO       SANTIAGO          756 CALLE PAZ                                                             ARECIBO                     PR006123533

The example addresses posted previously may have been imperfectly formed, but the char positions that I am looking for are indeed 149-157. Regardless, the code examples would provide enough guidance that even if my char positions were wrong (they aren't) I would be able to make minor modifications to fit the data.

---------- Post updated at 02:06 AM ---------- Previous update was at 01:58 AM ----------

dennis.jacob - Your awk one liner works great!
Just made one tiny modification:
Code:
awk 'NF==1 { ++A[$0] } NF>1 {s=substr($0,149,5)} A[s]' zips dat_file

Because I need to match on the 5 digit zip code, not the 9 digit.

Thanks a lot. Now I will try to unpack this one liner so I can build these in the future.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. UNIX for Advanced & Expert Users

Wanted to replace string in an .xlsx file in multiple ZIP Files

Hi , I am having a ZIP file containing an .xlsx file . Now i wanted to replace "GJ" to blank in the .xlsx file . I tried using the below code but not working , Please guide : #!/bin/bash log="/home/srikant/scripts/replacescriptFHO.log" date > $log echo "" >> $log echo initiating for FHO... (1 Reply)
Discussion started by: vipinmaster
1 Replies

3. Shell Programming and Scripting

Greping frequency for list of phrases is a separate file

Dear All I have a big set of data which I would like to summerize to have a better sense of it the problem is like this ... I have more than 200 files each related to a person which includes different sentences with specific elements (files in a directory) e.g. mark (one file in the directory)... (9 Replies)
Discussion started by: A-V
9 Replies

4. Shell Programming and Scripting

Compare two string in two separate file and delete some line of file

Hi all i want to write program with shell script that able compare two file content and if one of lines of file have # at the first of string or nothing find same string in one of two file . remove the line in second file that have not the string in first file. for example: file... (2 Replies)
Discussion started by: saleh67
2 Replies

5. Shell Programming and Scripting

Matching string from input to string of file

Hi, i want to know how to compare string of file with input string im trying following code: file_no=`paste -s -d "||||\n" a.txt | cut -c 1` #it will return collection number from file echo "enter number" read " curr_no" if ; then echo " current number already present" fi ... (4 Replies)
Discussion started by: a_smith
4 Replies

6. UNIX for Dummies Questions & Answers

search for a string in zip file

Hi, I know gzcat helps grep for a string inside a file that has been zipped using gzip command. However, how can the same be achieved for files zipped using zip command and any other compression commands you may know off. Thanks, Mohtashim (5 Replies)
Discussion started by: mohtashims
5 Replies

7. Shell Programming and Scripting

Specific file list to be zip

Hi, I need a specific list of files to be zip automatically. based on the criteria Criteria: 1. It should not be the current file and not less than 10 files e.g in a folder contails 100 files jan 50 -> contains ->45 zip files e.g. XXX.gz 5 normal log files e.g XXX.log ... (11 Replies)
Discussion started by: jagkoth
11 Replies

8. Shell Programming and Scripting

Renaming files by matching info from a separate file

Hi All, I could use a bit of help with this as I'm at a loss. I have a number of files all named accordingly: I have a separate text file that is as follows: What I want to do is end up with: I don't know how to do this, though I'm certain it can be done, and would rather learn how... (14 Replies)
Discussion started by: Demosthenes
14 Replies

9. UNIX for Dummies Questions & Answers

tar, zip multiple separate directories and move the results to another volume

TIA, I'm using FreeBSD 6 I have a series of Directories (A,B,C,...Z). Each directory has files and other directories within it. I want to compress the contents of each top directory into a single file so that I get an archive of each directory (for example, A.gzip) AND and want to move... (5 Replies)
Discussion started by: jccbin
5 Replies

10. UNIX for Dummies Questions & Answers

unzip .zip file and list the files included in the .zip archive

Hello, I am trying to return the name of the resulting file from a .zip archive file using unix unzip command. unzip c07212007.cef7081.zip Archive: c07212007.cef7081.zip SecureZIP for z/OS by PKWARE inflating: CEP/CEM7080/PPVBILL/PASS/G0063V00 I used the following command to unzip in... (5 Replies)
Discussion started by: oracledev
5 Replies
Login or Register to Ask a Question