ptew
asked on
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-00000000000 0000049410 2008/01/11 UNBILLED RECEIPTS
C90-00-00-1441-00000000000 0000550400 2008/01/11 UNBILLED RECEIPTS
C90-00-00-5165-00000000000 0000000000 2008/01/11 UNBILLED 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.
C90-00-00-1441-00000000000
C90-00-00-1441-00000000000
C90-00-00-5165-00000000000
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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?
Does that make sense?
ASKER
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!
ASKER
Now, would you explain it to me?