For Programmers: Free Programming Magazines  


Home > Archive > AWK > August 2007 > how to remove whitespaces in "current line"









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author how to remove whitespaces in "current line"
di98mase

2007-08-17, 3:58 am

Hi,

I have a log file consiting of a big number of hex blocks e.g.:

ac00dd00020061626364 65666768696a6b6c6d6e 6f707172737475767778
90000000030000000400 34553.......

These blocks are always 20 characters long separated with a
whitespace(blankspace). My problem is that when my awk program
recognizes the pattern which is always found in the first block in
this case, /^ac00dd0002/ the $0 contains a big line with blocks
separated with blanks. In my action section I want to print the
contents of hex data spanning over multiple "blocks" wich gives me
some problems because of the blanks.

What I would like to do in my action section is to remove all blanks
making the $0 into a continous line ended as usual with a NL. Is there
some smart way of doing this? I was thinking of using split() and than
sprintf to put all my elements of my array into a big line but since I
dont know the number of blocks I dont know how many strings I must
concatenate...


This is the looks of the line that I would like to have before I print
the contents of the string.
ac00dd0002006162636465666768696a6b6c6d6e
6f70717273747576777800000000300000004003
4553.......

John L

2007-08-17, 3:58 am


"di98mase" <di98mase@hotmail.com> wrote in message news:1187331360.675361.202740@k79g2000hse.googlegroups.com...
> Hi,
>
> I have a log file consiting of a big number of hex blocks e.g.:
>
> ac00dd00020061626364 65666768696a6b6c6d6e 6f707172737475767778
> 90000000030000000400 34553.......
>
> These blocks are always 20 characters long separated with a
> whitespace(blankspace). My problem is that when my awk program
> recognizes the pattern which is always found in the first block in
> this case, /^ac00dd0002/ the $0 contains a big line with blocks
> separated with blanks. In my action section I want to print the
> contents of hex data spanning over multiple "blocks" wich gives me
> some problems because of the blanks.
>
> What I would like to do in my action section is to remove all blanks
> making the $0 into a continous line ended as usual with a NL.


Use gsub() or perhaps gensub() to remove all the spaces in one go.

Or, if this only matters when you print it out, just print each "block"
in turn without intermediate spaces:

for (i = 1; i <= NF; i++)
{
printf("%s", $i) # i'th field or block, no spaces
}
printf("\n") # newline at the end

People often use printf to build up lines of output a bit at a time,
like this.

Or you might pre-process the input to remove the spaces (as above)
before feeding it to your main program. This has the advantage of
not cluttering up the logic of your main program. Post-processing
the output is also possible.

--
John.


di98mase

2007-08-17, 3:58 am

On 17 Aug, 09:18, "John L" <j...@lammtarra.notthisbit.fslife.co.uk>
wrote:
> "di98mase" <di98m...@hotmail.com> wrote in messagenews:1187331360.675361.=

202740@k79g2000hse.googlegroups.com...
>
>
>
>
>
> Use gsub() or perhaps gensub() to remove all the spaces in one go.
>
> Or, if this only matters when you print it out, just print each "block"
> in turn without intermediate spaces:
>
> for (i =3D 1; i <=3D NF; i++)
> {
> printf("%s", $i) # i'th field or block, no spaces
> }
> printf("\n") # newline at the end
>
> People often use printf to build up lines of output a bit at a time,
> like this.
>
> Or you might pre-process the input to remove the spaces (as above)
> before feeding it to your main program. This has the advantage of
> not cluttering up the logic of your main program. Post-processing
> the output is also possible.
>
> --
> John.- D=F6lj citerad text -
>
> - Visa citerad text -


Yes, gsub solved my problem...

Thanks John...

Ed Morton

2007-08-17, 6:58 pm

John L wrote:

> "di98mase" <di98mase@hotmail.com> wrote in message news:1187331360.675361.202740@k79g2000hse.googlegroups.com...
>
>
>
> Use gsub() or perhaps gensub() to remove all the spaces in one go.
>
> Or, if this only matters when you print it out, just print each "block"
> in turn without intermediate spaces:
>
> for (i = 1; i <= NF; i++)
> {
> printf("%s", $i) # i'th field or block, no spaces
> }
> printf("\n") # newline at the end


"print" is what's normally used to end the output with ORS, and "printf"
is a builtin not a function so it should be:

for (i = 1; i <= NF; i++)
{
printf "%s", $i # i'th field or block, no spaces
}
print # ORS at the end

Regards,

Ed.
Ed Morton

2007-08-17, 6:58 pm

Ed Morton wrote:

<snip>
> "print" is what's normally used to end the output with ORS, and "printf"
> is a builtin not a function so it should be:
>
> for (i = 1; i <= NF; i++)
> {
> printf "%s", $i # i'th field or block, no spaces
> }
> print # ORS at the end


print "" # ORS at the end
Radiskull

2007-08-18, 1:19 pm

Olsen Twins and Laetitia Casta Big Tits Mature Lesbian Sex!
http://www.worldfreemedia.com/d?movie=726071

Helen Hunt and Jessica Alba Lesbian XXXXing!
http://www.worldfreemedia.com/Play?movie=726071

Hilary Swank and Paris Hilton Having Fun On The Piano!
http://www.worldfreemedia.com/Media...sp?movie=726071

Christina Aguilera and Alyssa Milano , Lesbian Wrestler Loses Fight!
http://www.worldfreemedia.com/Play?clip=726071

Nikki Cox and Mariah Carey Licking Pussy!
http://www.worldfreemedia.com/PlayMovie.wmv?clip=726071
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com