Awk:  Need to evaluate a string and delete line where the string matches

Posted on 2008-11-06
Last Modified: 2013-12-26
We are running a legacy front-end system running in HP-UX 10.20.  The system produces an ASCII interface file that is uploaded into our GL system.  The interface file is positional with no delimiters as seen in this snippet:

C90-00-00-1441-0000000000000000494102008/01/11UNBILLED RECEIPTS
C90-00-00-1441-0000000000000005504002008/01/11UNBILLED RECEIPTS
C90-00-00-5165-0000000000000000000002008/01/11UNBILLED RECEIPTS

I want to evaluate the transaction amount of each line with is the 15 characters in positions 22 through 37.  If the string is 000000000000000, as in line three of my sample, I want to reject the line.  The accountants seem to think It's important however that only the lines with zero-dollar amounts are rejected ;).  I currently use AWK to substitute certain cost center portions.  I know CUT -c15-37 would extract the range I am looking for.  

How can this be accomplished using AWK or some other tool that one would find in an older UNIX environment?  

Thanks for reviewing this question.
Question by:ptew
    LVL 48

    Accepted Solution

    awk is fine, but sed is just as easy

    sed "/0000000000000002[0-9][0-9][0-9]\//D" file

    LVL 1

    Author Comment

    Wow, thanks for the fast response.  It works!  

    Now, would you explain it to me?
    LVL 48

    Expert Comment

    Without knowing what values columns 15-22 could contain, I assumed they may not necessarily be zeros, so I've specified sed to delete any line that matches 15 zeros followed by 4 digit date ending with a /.

    Does that make sense?
    LVL 1

    Author Comment

    It makes sense now.  The /0000000000000002[0-9][0-9][0-9]\/ is the search string where the [0-9] makes it match any year from 2000 to 2999 (hopefully we will have upgraded by then) and \/ is the slash after the year.  The /D tells it to delete the line when matching.  Thanks!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
    Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
    Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
    Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now