Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

how to remove whitespaces in "current line"
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
6f7071727374757677780000000030000000
40034553.......


Report this thread to moderator Post Follow-up to this message
Old Post
di98mase
08-17-07 08:58 AM


Re: how to remove whitespaces in "current line"
"di98mase" <di98mase@hotmail.com> wrote in message news:1187331360.675361.202740@k79g2000hs
e.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.



Report this thread to moderator Post Follow-up to this message
Old Post
John L
08-17-07 08:58 AM


Re: how to remove whitespaces in "current line"
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...


Report this thread to moderator Post Follow-up to this message
Old Post
di98mase
08-17-07 08:58 AM


Re: how to remove whitespaces in "current line"
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.

Report this thread to moderator Post Follow-up to this message
Old Post
Ed Morton
08-17-07 11:58 PM


Re: how to remove whitespaces in "current line"
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

Report this thread to moderator Post Follow-up to this message
Old Post
Ed Morton
08-17-07 11:58 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

Report this thread to moderator Post Follow-up to this message
Old Post
Radiskull
08-18-07 06:19 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

AWK archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 12:23 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.