Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SHELL

awk for loop

{ for (i=1;i<=8;i++) {print $i} }
# Examples 

# Print first 8 fields of each line of text file
awk '{ for (i=1;i<=8;i++) {printf $i" "} }' /path/to/text/file

# Print first 8 fields of each line of text file in reverse order
awk '{ for (i=8;i<=1;i--) {printf $i" "} }' /path/to/text/file

# Print all but the last two fields of each line of text file
awk '{ for (i=1;i<=(NF-2);i++) {printf $i" "} }' /path/to/text/file
 
PREVIOUS NEXT
Tagged: #awk #loop
ADD COMMENT
Topic
Name
2+4 =