Created
August 1, 2016 19:02
-
-
Save jainvishal/8bd2436f738eb54223edb69189eb1c4f to your computer and use it in GitHub Desktop.
Ignore a Field/Column using AWK
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## 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