Path: utzoo!attcan!uunet!snorkelwacker!mit-eddie!uw-beaver!sumax!thebes!happym!irv From: irv@happym.wa.com (Irving Wolfe) Newsgroups: comp.unix.questions Subject: Re: -F option for awk Keywords: awk field-separator Message-ID: <195@happym.wa.com> Date: 15 Aug 90 13:57:33 GMT References: <491@llnl.LLNL.GOV> Organization: Happy Man Corp., Seattle Lines: 40 In <491@llnl.LLNL.GOV> rjshaw@ramius.ocf.llnl.gov (Robert Shaw) writes: >print; or print $0; don't do the right thing because the lines come >out with spaces as the field separators instead of the character given >to the -F option. If you change any field, $1 to $NF, then print or print $0 re-composes $0 from all the individual fields, stringing them together with the output separator OFS which defaults to space unless you change it. If you don't touch any fields, awk should just print the originally input $0. Thus awk -F: '/^i/' /etc/passwd (here) produces irv:-------------:101:1:0000-Irving Wolfe(0000):/u/irv:/bin/gsh and awk '/^i/' /etc/passwd produces irv:-------------:101:1:0000-Irving Wolfe(0000):/u/irv:/bin/gsh exactly the same thing. Both print the /etc/passwd lines that begin with i exactly as is. But awk -F: '/^i/ {$2 = "hoho"; print}' /etc/passwd produces: irv hoho 101 1 0000-Irving Wolfe(0000) /u/irv /bin/gsh It will replace all the :s with spaces. You need awk -F: 'BEGIN {OFS = FS} /^i/ {$2 = "hoho"; print}' /etc/passwd which produces irv:hoho:101:1:0000-Irving Wolfe(0000):/u/irv:/bin/gsh -- Irving Wolfe Happy Man Corp. irv@happym.wa.com 206/463-9399 ext.101 4410 SW Point Robinson Road, Vashon Island, WA 98070-7399 fax ext.116 SOLID VALUE, the investment letter for Benj. Graham's intelligent investors Information free (sample $10 check or credit card): email patty@happym.wa.com