is there any way to print out, e.g. , $2 $3 $4.... $LAST,
i.e., just omitting $1 ?
Thanks,
++pac.
There are some awkish ways of doing this, but the most obvious thing to
do would be to try this:
cut -f2-
Hermann
thank you, however, I live on Plan 9, where there is no 'cut' ...
maybe it is wort to be ported ... is it in textutils?
++pac
Assuming that you're using the default FS, with a POSIX awk it's:
awk '{sub(/^[[:space:]]*([^[:space:]]*[[:space:]]*){1}/,"")}1'
and with GNU awk:
gawk --re-interval '...same...'
The number within the "{...}" is the number of initial fields to delete.
Ed.
I have the original UNIX awk, i think derived fom Sys7, or so, manpge
is here
http://plan9.bell-labs.com/magic/man2html/1/awk
so, no POSIX extensions, but,
I think for me ' ' , or \x20, should == [[:space:]]
but I still can't get what's going on...
I'm going to consult man gawk on linux box, but would be happy if you
could explain the above mentioned awk statement in a few words,
big thank you, cordially,
Peter.
awk '{print substr($0, 1+length($1)+1)}'
Then get a new awk as that's commonly referred to as "old, broken awk" for good
reason.
> i think derived fom Sys7, or so, manpge is here
> http://plan9.bell-labs.com/magic/man2html/1/awk
That man page describes "nextfile" and the ability to delete a whole array, both
of which are GNU awk extensions so that doesn't match what you said about which
awk you're using.
> so, no POSIX extensions, but,
> I think for me ' ' , or \x20, should == [[:space:]]
No, [[:space:]] is a character class that includes multiple white space
characters (blank, tab, newline, etc.), not just one.
> but I still can't get what's going on...
> I'm going to consult man gawk on linux box, but would be happy if you
> could explain the above mentioned awk statement in a few words,
> big thank you, cordially,
In awk the default FS represents any sequence of white space characters except
the RS. Using the default FS, any leading white space characters are ignored in
determining the fields, so $1 is the first sequence of non-white-space
characters in the record (line). This script:
awk '{sub(/^[[:space:]]*([^[:space:]]*[[:space:]]*){N}/,"")}1'
says:
awk '{sub(/ # replace
^[[:space:]]* # an initial sequence of zero or more spaces
( # followed by a group of (
[^[:space:]]* # zero or more non-spaces
[[:space:]]* # followed by zero or more spaces
){N} # ) repeated N times
/, # with
"")} # a null string
1' # and print the current record
So the initial "^[[:space:]]*" causes any leading white space to be skipped and
"([^[:space:]]*[[:space:]]*)" matches a field plus the spaces after that field.
The "{N}" says how many of those field-then-FS groups to match. Replacing it all
with a null string obviously deletes the full regexp, i.e. leading white space
followed by N field-then-FS groups.
Ed.
That is not a solution. Look:
$ echo " abc def" | awk '{print substr($0, 1+length($1)+1)}'
abc def
$ echo " abc def" | gawk --re-interval
'{sub(/^[[:space:]]*([^[:space:]]*[[:space:]]*){1}/,"")}1'
def
$ echo "abc def" | awk '{print substr($0, 1+length($1)+1)}'
def
$ echo "abc def" | gawk --re-interval
'{sub(/^[[:space:]]*([^[:space:]]*[[:space:]]*){1}/,"")}1'
def
Regards,
Ed.
If you wanted something that will only work if you have no leading white space
and just one blank between fields, that'd just be:
awk '{sub(/[^ ]* /,"")}1'
Ed,
>
> That is not a solution. Look:
>
> $ echo " abc def" | awk '{print substr($0, 1+length($1)+1)}'
> abc def
>
> $ echo " abc def" | gawk --re-interval
> '{sub(/^[[:space:]]*([^[:space:]]*[[:space:]]*){1}/,"")}1'
> def
>
>
> $ echo "abc def" | awk '{print substr($0, 1+length($1)+1)}'
> def
>
> $ echo "abc def" | gawk --re-interval
> '{sub(/^[[:space:]]*([^[:space:]]*[[:space:]]*){1}/,"")}1'
> def
>
>
> Regards,
>
> Ed.
>
If you want something that will work if you have no leading white space and just
one FS between fields, that'd just be:
awk '{sub(/[^ ]* /,"")}1'
Peter, aka ++pac
Well, using 1 tool instead of 3 seems like it'd keep things as simple as
possible. The awk solution I gave you originally is intended to satisfy your
question in general, but if you're looking at a mush of sed, tr, length(), etc.
to do what you want then you must have a very restricted input and set of
requirements so if you want to post whatever your pipeline solution is and some
small set of sample input and expected output, we can show you how to do it
simply with just awk.
Ed.
Excellent Ed! I guess you had your promised coffee :-)
For the OP, in case you don't mind losing the spacing
here's a quick and dirty:
$ echo ' one two three four ' | gawk '{$1=""} 1'
two three four
$
Right, and a simple sub at the back would take care of the leading white space:
awk '{$1="";sub(/^ +/,"")}1'
Ed.
ruby -pne 'sub(/^\s*\S+\s+/, "")' file
=== input ===
a b c d e
a b c d e
a b c d e
=== output ===
b c d e
b c d e
b c d e
% cat foo2
1,2,3,4
5,6,7,8
9,10,11,12
% gawk '{FS=","; $2=""; $3=""; } 1' foo2
1,2,3,4
5 8
9 12
%
See "Advanced Notes: Changing FS Does Not Affect the Fields" here:
http://www.gnu.org/manual/gawk/gawk.html#Field-Splitting-Summary
You made a small typo. You meant to write:
BEGIN {FS=","}
{ $2=""; $3="";print }
You may want to research the "BEGIN" keyword in AWK.