13.13. Finding a Character in a ColumnHere's an idea for finding lines that have a given character in a column. Use the following simple awk (Section 20.10) command: % awk 'substr($0,n,1) == "c"' filename where c is the character you're searching for, and n is the column you care about. Where would you do this? If you're processing a file with strict formatting, this might be useful; for example, you might have a telephone list with a # in column 2 for "audio" telephone numbers, $ for dialup modems, and % for fax machines. A script for looking up phone numbers might use an awk command like this to prevent you from mistakenly talking to a fax machine. If your data has any TAB characters, the columns might not be where you expect. In that case, use expand on the file, then pipe it to awk. --JP and ML Copyright © 2003 O'Reilly & Associates. All rights reserved. |
|