Is there a way to print everything after a positional parameters using awk? What I would like the following command to print is p4 p5 p6 p7echo p1 p2 p3 p4 p5 p6 p7 | awk '{print $4...}'Furthermore, is it possible to print between two positional parameters. The following printing p4 p5 p6echo p1 p2 p3 p4 p5 p6 p7 | awk '{print $4...$6}'I would like to avoid using regex and having to type: awk '{print $4 $5 $6}'
How To Use Awk To Print Between Two Positional Parameters
awk
If your parameters are dependably separated by exactly one space each, you could use cut as follows:echo p1 p2 p3 p4 p5 p6 p7 | cut -d' ' -f4-   # For p4 onwardsecho p1 p2 p3 p4 p5 p6 p7 | cut -d' ' -f4-6  # For p4 to p6If you want whitespace separated parameters the way awk parses them, dependably, it gets more complicated.  For an example of what I'm talking about and how the above may not always do what you want, try:printf '%s   ' p1 p2 p3 p4 p5 p6 p7 | cut -d' ' -f4-printf '%s   ' p1 p2 p3 p4 p5 p6 p7 | cut -d' ' -f4-6You can see that cut is treating each space as a delimiter, rather than any sequence of consecutive spaces as a delimiter the way awk does.  You can force awk to do what you want with a for loop:echo p1 p2 p3 p4 p5 p6 p7 | awk '{for (a=4;a<=NF;a++) {printf %s , $a} printf \n}'However this does leave a trailing space at the end of the line.  This can be addressed, but it gets messier and messier.  Depending on your requirements, the cut command may be just fine.