Code Comments
Programming Forum and web based access to our favorite programming groups.Right off the bat; fix one issue here @ work & they think I move mountains =P Secondly. Windows based using GAWK or AWK95.EXE. Need: Search a file for spaces....delete ONE from 1st instance in line, pad 2 spaces to 2nd instance of SAME line EG: "5290Companies Name 12345678920070814RTRN001000000000 0000 " should be "5290Companies Name 12345678920070814RTRN001000000000 0000 " del. 1 ^ add 2 ^
Post Follow-up to this messageOn Wed, 15 Aug 2007 08:02:27 -0700, i_robot73 wrote: > Right off the bat; fix one issue here @ work & they think I move > mountains =P > Secondly. Windows based using GAWK or AWK95.EXE. > > Need: > > Search a file for spaces....delete ONE from 1st instance in line, pad > 2 spaces to 2nd instance of SAME line > > EG: > > "5290Companies Name 12345678920070814RTRN001000000000 > 0000 " > > should be > > "5290Companies Name 12345678920070814RTRN001000000000 > 0000 " > > del. 1 > ^ add 2 ^ It appears that you want to delete the last space before the last field and add two at the end of the line sub( " " $(NF), $NF ) print $0 " " should do that in gawk (it does in my test). -- T.E.D. (tdavis@umr.edu)
Post Follow-up to this messageSorry, damn line wraps & crap....
In the same record:
1st space-padding, delete a space before the '123456789<date>'
2nd space-padding, add two spaces
I was able to do it with 2 runs through AWK using a temporary file,
but want to see if I can't cut it down to something 'smaller' code-
wise.
current code:
AWK "{gsub(\"U 2\",\"U 2\");print}"
orig.file>temp.file
AWK "{gsub(\"N001000000000 0\",\"N001000000000 0\");print}"
temp.file>final.file
On Aug 15, 4:46 pm, Ted Davis <tda...@umr.edu> wrote:
> On Wed, 15 Aug 2007 08:02:27 -0700, i_robot73 wrote:
>
>
>
>
>
>
>
>
> It appears that you want to delete the last space before the last field
> and add two at the end of the line
>
> sub( " " $(NF), $NF )
> print $0 " "
>
> should do that in gawk (it does in my test).
>
> --
> T.E.D. (tda...@umr.edu)
Post Follow-up to this messageI was able to do it in one line...but prob. not the BEST way (one big
line, so watch the wraps)
AWK "{sub(\"U 2\",\"U 2\");print}" ".\<input>" |
AWK "{sub(\"RTRN001000000000 0000\",\"RTRN001000000000
0000\");print}">".\<output>"
How about padding lines to a certain length??
Post Follow-up to this messagei_robot73@hotmail.com wrote:
[ please don't top-post, fixed below ]
>
> On Aug 15, 4:46 pm, Ted Davis <tda...@umr.edu> wrote:
>
>
>
>
> Sorry, damn line wraps & crap....
>
> In the same record:
> 1st space-padding, delete a space before the '123456789<date>'
> 2nd space-padding, add two spaces
>
> I was able to do it with 2 runs through AWK using a temporary file,
> but want to see if I can't cut it down to something 'smaller' code-
> wise.
>
> current code:
>
> AWK "{gsub(\"U 2\",\"U 2\");print}"
> orig.file>temp.file
> AWK "{gsub(\"N001000000000 0\",\"N001000000000 0\");print}"
> temp.file>final.file
>
>
If I understand you correctly, all you need with gawk is:
{print gensub(/ (123456789[^ ]*)/,"\\1 ","")}
e.g. (UNIX syntax):
$ echo "a 12345678920070814RTXXX c"
a 12345678920070814RTXXX c
$ echo "a 12345678920070814RTXXX c" |
gawk '{print gensub(/ (123456789[^ ]*)/,"\\1 ","")}'
a 12345678920070814RTXXX c
If you don't gave gawk, just use 2 subs():
$ echo "a 12345678920070814RTXXX c" |
awk -v p="123456789" '{sub(" "p,p);sub(p"[^ ]*","& ");print}'
a 12345678920070814RTXXX c
Regards,
Ed.
Post Follow-up to this messagei_robot73@hotmail.com wrote:
> I was able to do it in one line...but prob. not the BEST way (one big
> line, so watch the wraps)
>
> AWK "{sub(\"U 2\",\"U 2\");print}" ".\<input>" |
> AWK "{sub(\"RTRN001000000000 0000\",\"RTRN001000000000
> 0000\");print}">".\<output>"
>
>
>
> How about padding lines to a certain length??
>
Show some sample input and expected output if you'd like advice. It's
bnot clear what you're asking above. Also when replying to a netnews
posting like this (NOT a web forum), you need to include enough context
that your current posting stands alone so the rest of us don't have to
go digging back through the previous postings to figure out what this
one is talking about.
Ed.
Post Follow-up to this messageOn Thu, 16 Aug 2007 10:59:43 -0500, Ed Morton wrote: > Show some sample input and expected output if you'd like advice. It's > bnot clear what you're asking above. Also when replying to a netnews > posting like this (NOT a web forum), you need to include enough context > that your current posting stands alone so the rest of us don't have to > go digging back through the previous postings to figure out what this > one is talking about. Especially when we are using Pan and the other message is not even on this machine, but on one many miles away (Agent syncs correctly with a newsrc, but Pan doesn't download messages that have been read on the other machine but don't exist on the current one). -- T.E.D. (tdavis@umr.edu)
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.