This line 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.
from this answer is not bad but the natural spacing is gone.
Please then compare it to this one:
Then you'd see the difference.
Even
ls -la | awk '{$1=$2=""; print}'
which is based on the answer voted best thus far is not preserve the formatting.Thus I would use the following, and it also allows explicit selective columns in the beginning:
Note that every space counts for columns too, so for instance in the below, columns 1 and 3 are empty, 2 is INFO and 4 is:
Printing out columns starting from #2 (the output will have no trailing space in the beginning):
Would this work?
It leaves some whitespace in front though.
Most solutions with awk leave an space. The options here avoid that problem.
Option 1
A simple cut solution (works only with single delimiters):
Option 2
Forcing an awk re-calc sometimes remove the added leading space (OFS) left by removing the first fields (works with some versions of awk):
Option 3
Printing each field formatted with
printf
will give more control:However, all previous answers change all repeated FS between fields to OFS. Let's build a couple of option that do not do that.
Option 4 (recommended)
A loop with sub to remove fields and delimiters at the front.
And using the value of FS instead of space (which could be changed).
Is more portable, and doesn't trigger a change of FS to OFS: NOTE: The
^[FS]*
is to accept an input with leading spaces.Option 5
It is quite possible to build a solution that does not add extra (leading or trailing) whitespace, and preserve existing whitespace(s) using the function
gensub
from GNU awk, as this:It also may be used to swap a group of fields given a count
n
:Of course, in such case, the OFS is used to separate both parts of the line, and the trailing white space of the fields is still printed.
NOTE:
[FS]*
is used to allow leading spaces in the input line.Perl solution:
These command-line options are used:
-n
loop around every line of the input file, do not automatically print every line-l
removes newlines before processing, and adds them back in afterwards-a
autosplit mode – split input lines into the @F array. Defaults to splitting on whitespace-e
execute the perl codesplice @F,0,1
cleanly removes column 0 from the @F arrayjoin " ",@F
joins the elements of the @F array, using a space in-between each elementPython solution:
python -c "import sys;[sys.stdout.write(' '.join(line.split()[1:]) + '\n') for line in sys.stdin]" < file
There's a duplicate question with a simpler answer using cut:
-d
specifies the delimeter (space),-f
specifies the list of columns (all starting with the 2nd)