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

printing multiple spaces with awk
Hallo,

I have a listing with following form:

a  b c d  xx y   zz.txt
f r  f     g    yz x  xx zzz.doc


Report this thread to moderator Post Follow-up to this message
Old Post
Brigitte Selch
03-20-04 01:23 AM


Re: printing multiple spaces with awk
In article <7966a6cc.0402260540.79f08419@posting.google.com>,
Brigitte Selch <Brigitte_Selch@mn.man.de> wrote:
>Hallo,
>
>       I have a listing with following form:
>
>       a  b c d  xx y   zz.txt
>       f r  f     g    yz x  xx zzz.doc
>
>       .
>       .
>       .
>
>       Now ich want to eliminate the first 4 columns and print the all
>       following columns as they are (with multiple blanks, because they ar
e
>       filenames).
>       In my example:
>
>       xx y   zz.txt
>       yz x  xx zzz.doc

I'm not sure I understand the underlying problem - what exactly is this
data, and, if they are filenames, why do you need to preserve the
inter-field spacing - but anyway, this is a well-known "feature" of AWK (*),
and here is one solution (**).

{
for (i=0; i<4; i++)
sub("[ \t]*"$1"[ \t]*","")
print
}

(*) It has its plusses and minusses.

(**) Modulu issues of reg ex magic chars in $1.


Report this thread to moderator Post Follow-up to this message
Old Post
Kenny McCormack
03-20-04 01:23 AM


Re: printing multiple spaces with awk
Hi Brigitte,

index($0,$5)            returns the index of $5 in the string $0.
substr($0,index($0,$5)) returns the rest of $0, starting at the
beginning of $5.

awk '{print substr($0,index($0,$5));}'

HTH,
Stefan

Brigitte Selch schrieb:
>        I have a listing with following form:
>
>        a  b c d  xx y   zz.txt
>        f r  f     g    yz x  xx zzz.doc
[...]
>        Now ich want to eliminate the first 4 columns and print the all
>        following columns as they are (with multiple blanks, because they a
re
>        filenames).
>        In my example:
>
>        xx y   zz.txt
>        yz x  xx zzz.doc

Test:

awk '{print substr($0,index($0,$5));}' << EOF
>        a  b c d  xx y   zz.txt
>        f r  f     g    yz x  xx zzz.doc
> EOF
xx y   zz.txt
yz x  xx zzz.doc


Report this thread to moderator Post Follow-up to this message
Old Post
Stefan Lagotzki
03-20-04 01:23 AM


Re: printing multiple spaces with awk
Hello,

Wow, it works.

Thank you very much,
Brigitte

Report this thread to moderator Post Follow-up to this message
Old Post
Brigitte Selch
03-20-04 01:23 AM


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 10:34 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.