Skip to content

Instantly share code, notes, and snippets.

@jainvishal
Created August 1, 2016 19:02
Show Gist options
  • Select an option

  • Save jainvishal/8bd2436f738eb54223edb69189eb1c4f to your computer and use it in GitHub Desktop.

Select an option

Save jainvishal/8bd2436f738eb54223edb69189eb1c4f to your computer and use it in GitHub Desktop.
Ignore a Field/Column using AWK
## usage awk -F',' -v FieldToIgnore=2 -f ignoreField.awk datafile
## This just gives the basic idea. More error detection can be done.
{
if (FieldToIgnore == "" || FieldToIgnore <= 0) {
print "Incorrect/Missing field"
print "usage: awk -F',' -v FieldToIgnore=<FieldumnToIgnore> -f ignoreField.awk datafile"
exit
}
for (i = 1; i <= NF; i++)
if (i == FieldToIgnore) {
if(i == NF)
printf("%s", OFS);
continue
}
else
printf ("%s%s", $i, (i != NF) ? OFS : ORS)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment