tags:

views:

352

answers:

3

right now I have this line, and it worked until I had whitespace in the second field.

svn status | grep '\!' | gawk '{print $2;}' > removedProjs

is there a way to have awk print everything in $2 or greater? ($3, $4.. until we don't have anymore columns?)

I suppose I should add that I'm doing this in a windows environment with cygwin.

+2  A: 

You could use a for-loop to loop through printing fields $2 through $NF (built-in variable that represents the number of fields on the line).

Edit: Since "print" appends a newline, you'll want to buffer the results:

awk '{out=""; for(i=2;i<=NF;i++){out=$out" "$i}; print $out}'

Alternatively, use printf:

awk 'for(i=2;i<=NF;i++){printf "%s ", $i}; printf "\n"}'
VeeArr
So I tried this, but think I'm missing something.. here is what I didsvn status | grep '\!' | gawk '{for (i=1; i<=$NF; i++)print $i " ";}' > removedProjs
Andy
Since print appends a newline, you'll want to buffer the results. See my edit.
VeeArr
When I do that I get a msg that says ^ unterminated string
Andy
heres my exact line:svn status | grep '\!' | gawk "{out=""; for(i=2; i<= NF; i++){out=$out" "$i;} print $out}" > removedProjs
Andy
It is because you are using " " to enclose your awk script. Use ' ' instead. Also, it may be simpler to just use printf instead of buffering the result.
VeeArr
K, figured out that the error is because I use double quotes, but I think something with cygwin doesn't like single quotes, cause then it says it is missing the file.
Andy
A: 

Would this work?

awk '{print substr($0,length($1)+1);}' < file

It leaves some trailing whitespace in front though.

whaley
+3  A: 

will print all but very first column:

cat somefile | awk '{$1=""; print $0}'    

will print all but two first columns:

cat somefile | awk '{$1=$2=""; print $0}'
zed_0xff
thanks, this ended up working
Andy
useless use of cat.
ghostdog74