Home > Archive > AWK > March 2004 > printing multiple spaces with awk
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 |
printing multiple spaces with awk
|
|
| Brigitte Selch 2004-03-19, 8:23 pm |
| 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
| |
| Kenny McCormack 2004-03-19, 8:23 pm |
| 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 are
> 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.
| |
| Stefan Lagotzki 2004-03-19, 8:23 pm |
| 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 are
> 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
| |
| Brigitte Selch 2004-03-19, 8:23 pm |
| Hello,
Wow, it works.
Thank you very much,
Brigitte
|
|
|
|
|