Here's one way to do it with Awk that's relatively easy to understand:
awk '{print substr($0, index($0, $3))}'
This is a simple awk command with no pattern, so action inside {}
is run for every input line.
The action is to simply prints the substring starting with the position of the 3rd field.
$0
: the whole input line$3
: 3rd fieldindex(in, find)
: returns the position of find
in string in
substr(string, start)
: return a substring starting at index start
If you want to use a different delimiter, such as comma, you can specify it with the -F option:
awk -F"," '{print substr($0, index($0, $3))}'
You can also operate this on a subset of the input lines by specifying a pattern before the action in {}
. Only lines matching the pattern will have the action run.
awk 'pattern{print substr($0, index($0, $3))}'
Where pattern can be something such as:
/abcdef/
: use regular expression, operates on $0 by default.$1 ~ /abcdef/
: operate on a specific field.$1 == blabla
: use string comparisonNR > 1
: use record/line numberNF > 0
: use field/column number