replacing nulls in date string 
Author Message
 replacing nulls in date string

I have a spooled Unix print files with several occurences of 8 digit format
(mmddyyyy) date strings which are print nulls where the month or day is <10.

I need to insert a "0" in the <10 months or days null and leave the print
intact. I do not have the source to the print program.

Would appreciate any suggestions on using awk and/or sed with reg
expressions to accomplish this.

Thanks



Mon, 05 Nov 2001 03:00:00 GMT  
 replacing nulls in date string


Quote:
> I have a spooled Unix print files with several occurences of 8 digit
> format (mmddyyyy) date strings which are print nulls where the month
> or day is <10.

> I need to insert a "0" in the <10 months or days null and leave the
> print intact. I do not have the source to the print program.

> Would appreciate any suggestions on using awk and/or sed with reg
> expressions to accomplish this.

Are there other NULLs that you want to leave as-is? If not, tr may be
the best alternative:  tr "\000" 0 < input > output  .

If there are other NULLs and you only want to change those occurring in
date strings, then you need to use gawk. Other awk implementations have
trouble with NULLs, and I believe sed is also unable to handle NULLs.
Here's the best I could come up with.

awkscript:
----------
match($0,/(^|[^0-9])\000[0-9][0-9\000][0-9]{5}([^0-9]|$)/){
    do {
        $0 = substr($0, 1, RSTART - 1) "0" substr($0, RSTART + 1)
    } while (match($0,/(^|[^0-9])\000[0-9][0-9\000][0-9]{5}([^0-9]|$)/))

Quote:
}

match($0,/(^|[^0-9])[0-9]{2}\000[0-9]{5}([^0-9]|$)/){
    do {
        $0 = substr($0, 1, RSTART + 1) "0" substr($0, RSTART + 3)
    } while (match($0,/(^|[^0-9])[0-9]{2}\000[0-9]{5}([^0-9]|$)/))
Quote:
}

{print}

command line:
-------------
gawk --posix -f awkscript input > output

I suspect this would be much easier in perl.

--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---



Mon, 05 Nov 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Null string as parameter to DATE()

2. string.replace() can't replace newline characters???

3. Search a spreadsheet for a character string (date) and read to another date

4. null date?

5. PoPy and Null dates

6. convert integer string to date string

7. Set a text string to a NULL value

8. NULL String for Win API

9. How to assign null string to a variable?

10. Fortran and C null terminated strings

11. PL/I and C null terminated strings?

12. PL/I and C null terminated strings?

 

 
Powered by phpBB® Forum Software