21.07.2015 Views

GAWK: Effective AWK Programming

GAWK: Effective AWK Programming

GAWK: Effective AWK Programming

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

218 <strong>G<strong>AWK</strong></strong>: <strong>Effective</strong> <strong>AWK</strong> <strong>Programming</strong>}if (fieldlist == "") {print "cut: needs list for -c or -f" > "/dev/stderr"exit 1}if (by_fields)set_fieldlist()elseset_charlist()set_fieldlist is used to split the field list apart at the commas and into an array.Then, for each element of the array, it looks to see if it is actually a range, and if so, splitsit apart. The range is verified to make sure the first number is smaller than the second.Each number in the list is added to the flist array, which simply lists the fields that willbe printed. Normal field splitting is used. The program lets awk handle the job of doingthe field splitting:function set_fieldlist( n, m, i, j, k, f, g){n = split(fieldlist, f, ",")j = 1 # index in flistfor (i = 1; i = g[2]) {printf("bad field list: %s\n",f[i]) > "/dev/stderr"exit 1}for (k = g[1]; k

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!