Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!rutgers!ucla-cs!zen!ucbvax!hplabs!well!daniels From: daniels@well.UUCP (Dan Smith, Social Mammal...) Newsgroups: comp.unix.questions Subject: An awk question or two... Message-ID: <3931@well.UUCP> Date: Fri, 11-Sep-87 19:06:44 EDT Article-I.D.: well.3931 Posted: Fri Sep 11 19:06:44 1987 Date-Received: Sat, 12-Sep-87 22:28:32 EDT Distribution: na Lines: 84 Keywords: awk ranges Hello, I've been using awk for a few weeks, read through the documentation, the "Supplemental Document for awk" by John Pierce (a good paper to have!), and the chapter in "Unix Papers" called "awk Power Plays" by David Huelsbeck. Still, I have a few problems that I haven't figured out, and the documentation doesn't seem to have anything appropriate... Command lines, passing variables to awk: awk -f comline.awk comvar=\"SUB\" ascii.h this is the file comline.awk: comvar { print } "ascii.h" has a couple of lines that have "SUB" and, the result: 323 bin/src :-} !aw awk -f comline.awk comvar=\"SUB\" ascii.h awk: syntax error near line 1 awk: bailing out near line 1 324 bin/src :-} Now, you might look at this and say, "why dont you use grep"? I'm not done yet, it gets more fun... What I want to do is to pass *two* command line variables, and have awk work on the lines within the two patterns -- such as: comlinevar1, comlinevar2 { (some awk commands) } Here's where another problem springs up. The file I'll be awk'ing a lot has a lot of info that pertains to programs... a sample format from the file looks like: -c start of data... -ds data -f bhuff.bin -n -f bhuff.c -f dirinfo -c basename only files for data... -b dirinfo -b str_name -c filename extensions for data... -e bin -e old -c end of the directory data... -de data -c start of src...ame> line, and pick out lines that start with "-f" (files) in that directory - just that directory... I was thinking that I could do something like: (comlinevar1="-ds", comlinevar2="-de") comlinevar1, comlinevar2 { /-f/ { print $2 } } Obviously, this violates a some things about awk. All of the examples that I saw of awk didn't seem to address this sort of proceessing. Maybe sed is better for this. The basic idea is: get a range of lines from a file, and print selected ones from that range. I want to be able to use command line arguments, so that I dont have to write 20-30 scripts that all do pretty much the exact same thing. I'm probably missing something really obvious in the documentation - I dont have a lot of examples to learn from; even if you haven't solved this particular sort of problem, and you've written some stuff in awk that you dont mind mailing, I would love to get a copy. I certainly hope there is a good way to do this in awk - it's certainly pretty useful for other types of text processing problems, and this problem doesn't seem like one that would hit a limitation in awk. thanks much for any light you can shed on this! dan dan smith, island graphics, marin co., ca | "I am responsible for everything uucp: ..!ucbvax!ucbcad!well!island!daniel | I've ever said since 1960!" uucp: ..!ptsfa!unicom!daniel !well!daniels | (415) 892 TANK (h) 491 1000 (w)