Hello, On Mon, 21 Jan 2019, Michael Orlitzky wrote: >On 1/21/19 6:50 PM, Adam Carter wrote: >> I need to clean up a file which has IP addresses with leading zeros in >> some of the octets so I need to make, say, .09 into .9 >> >> How do i do that in sed/awk/whatever? > >The first thing you should do is construct a bunch of test cases, with all of >the possible input representations and what you think the output >representation should be. Then, you should write a program in something other >than bash that passes all of the test cases. It's not as easy as it sounds; >for example: > > * What happens to 0.1.2.3? > > * What happens to 01.2.3.4? > > * What happens to 1.2.3.0? > > * What happens to 1.2.000.3? > >You need a parser, not a regular expression. (You can do it with a regex, but >it's going to be one of those comical twelve-page-long things.)
$ printf '0.1.2.3 01.2.3.4 1.2.3.0 1.2.000.3\n' | \ sed 's/0*\([[:digit:]]\+\)/\1/g' 0.1.2.3 1.2.3.4 1.2.3.0 1.2.0.3 HTH, -dnh -- printk(KERN_DEBUG "adintr: Why?\n"); linux-2.6.19/sound/oss/ad1848.c