I'd like to copy commands from my recent command history into a file, but the history looks like this:
568 find . -name "*.txt" -mtime -1 -print -exec awk '$9 != "" && NR <= 10' {} \;
569 find . -name "*.txt" -mtime -1 -print -exec awk '$9 != "" && n < 10 {print; n++}' {} \;
570 history 10
I want to strip off the numbers on the left. Is there a short way to do this in awk without explicitly using $2 $3 $4 etc. to output everything but the first field?
if you don't mind the little space in front
awk '{$1="";print}' file
otherwise, do an extra sub/gsub to get rid of it. The other way is to use a for loop
awk '{for(i=2;i<=NF;i++) printf "%s " ,$i}' file
Borrowing from pax's solution, the awk version using regex (who says you need sed ) :)
awk '{gsub(/^ *[^ ]* */,"")}1' file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With