bash awk first 1st column and 3rd column with everything after

ooXei1sh picture ooXei1sh · Feb 10, 2013 · Viewed 17.1k times · Source

I am working on the following bash script:

# contents of dbfake file
1 100% file 1
2 99%  file name 2
3 100% file name 3

#!/bin/bash

# cat out data
cat dbfake |

# select lines containing 100%
grep 100% |

# print the first and third columns
awk '{print $1, $3}' |

# echo out id and file name and log
xargs -rI % sh -c '{ echo %; echo "%" >> "fake.log"; }'

exit 0

This script works ok, but how do I print everything in column $3 and then all columns after?

Answer

mjuarez picture mjuarez · Feb 10, 2013

You can use cut instead of awk in this case:

  cut -f1,3- -d ' '