[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 329
  • Last Modified:

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

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.
0
ptew
Asked:
ptew
  • 2
  • 2
1 Solution
 
TintinCommented:
awk is fine, but sed is just as easy

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

0
 
ptewAuthor Commented:
Wow, thanks for the fast response.  It works!  

Now, would you explain it to me?
0
 
TintinCommented:
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?
0
 
ptewAuthor Commented:
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!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now