Re: Expanding tabs (was Re: kwik way?)
Hi, Reference: From: Gary Kline kl...@thought.org Date: Wed, 18 May 2011 12:10:01 -0700 Message-id: 20110518191001.ga22...@thought.org Gary Kline wrote: On Wed, May 18, 2011 at 01:09:36PM -0500, Dan Nelson wrote: Date: Wed, 18 May 2011 13:09:36 -0500 From: Dan Nelson dnel...@allantgroup.com Subject: Re: Expanding tabs (was Re: kwik way?) To: Gary Kline kl...@thought.org Cc: FreeBSD Mailing List freebsd-questions@freebsd.org In the last episode (May 18), Gary Kline said: should i use tr or sed to turn \t into ? --i.e., tabs into spaces. tr or expand (depending on whether you want to honor the intent of the tab or not). sed is overkill. yeah, agree. i grabbed an old `for k in *;do' script and used tr on 80+ files. [facing reality, i'm throwing in the towel on hacking. wanted something easy!] http://berklix.com/~jhs/src/bsd/jhs/bin/public/tab/tab.c tab.1 Makefile works on the assumption of 8,16 etc, not other minorities eg ts=4 Mature code 1988 till now. Hasn't burnt me yet. Cheers, Julian -- Julian Stacey, BSD Unix Linux C Sys Eng Consultants Munich http://berklix.com Mail plain text; Not quoted-printable, Not HTML, Not base 64. Reply below text sections not at top, to avoid breaking cumulative context. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: Expanding tabs (was Re: kwik way?)
On Fri, May 20, 2011 at 04:12:35PM +0200, Julian H. Stacey wrote: Date: Fri, 20 May 2011 16:12:35 +0200 From: Julian H. Stacey j...@berklix.com Subject: Re: Expanding tabs (was Re: kwik way?) To: Gary Kline kl...@thought.org cc: Dan Nelson dnel...@allantgroup.com, FreeBSD Mailing List freebsd-questions@freebsd.org X-URL: http://www.berklix.com Hi, Reference: From: Gary Kline kl...@thought.org Date: Wed, 18 May 2011 12:10:01 -0700 Message-id: 20110518191001.ga22...@thought.org Gary Kline wrote: On Wed, May 18, 2011 at 01:09:36PM -0500, Dan Nelson wrote: Date: Wed, 18 May 2011 13:09:36 -0500 From: Dan Nelson dnel...@allantgroup.com Subject: Re: Expanding tabs (was Re: kwik way?) To: Gary Kline kl...@thought.org Cc: FreeBSD Mailing List freebsd-questions@freebsd.org In the last episode (May 18), Gary Kline said: should i use tr or sed to turn \t into ? --i.e., tabs into spaces. tr or expand (depending on whether you want to honor the intent of the tab or not). sed is overkill. yeah, agree. i grabbed an old `for k in *;do' script and used tr on 80+ files. [facing reality, i'm throwing in the towel on hacking. wanted something easy!] http://berklix.com/~jhs/src/bsd/jhs/bin/public/tab/tab.c tab.1 Makefile works on the assumption of 8,16 etc, not other minorities eg ts=4 Mature code 1988 till now. Hasn't burnt me yet. Cheers, Julian -- Julian Stacey, BSD Unix Linux C Sys Eng Consultants Munich http://berklix.com Mail plain text; Not quoted-printable, Not HTML, Not base 64. Reply below text sections not at top, to avoid breaking cumulative context. Been messing with tab.c [on my desktop, ubuntu]; it compiles with gcc tab.c, etc. the man page displays cleanly. thing is: how to i get, say hello, \t how are \t you to translate to hello, how are you [?] in other words, tab - 1 space rather than the defaul of 4. tx, gary -- Gary Kline kl...@thought.org http://www.thought.org Public Service Unix Journey Toward the Dawn, E-Book: http://www.thought.org The 7.98a release of Jottings: http://jottings.thought.org ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: Expanding tabs (was Re: kwik way?)
Gary Kline kl...@thought.org wrote: how to i get, say hello, \t how are \t you to translate to hello, how are you [?] in other words, tab - 1 space rather than the defaul of 4. You only need something like expand or tab.c if you want to convert each tab to a variable number of spaces depending on column position. If you just want each tab to become a single space, which is what I think your in other words says: $ tr '\011' ' ' input output If you want each _sequence of one or more tabs and/or spaces_ to become a single space, which is what the example looks like: $ sed 's/[ ^I][ ^I]*/ /g' input output (^I represents an actual tab character; in bash I get that by the two-keystroke sequence CtrlV CtrlI but other shells may vary. Dunno offhand if sed would understand the \t or \011 notation.) ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
RE: kwik way?
-Original Message- From: owner-freebsd-questi...@freebsd.org [mailto:owner-freebsd- questi...@freebsd.org] On Behalf Of Gary Kline Sent: Wednesday, May 18, 2011 10:42 AM To: FreeBSD Mailing List Subject: kwik way? should i use tr or sed to turn \t into ? --i.e., tabs into spaces. Depends on how you do it in sed. The y/// operator is faster than s/// when transliterating a single character globally. If you use y/// instead of s///, then sed performance should be on-par with tr. Below are some performance metrics involving a 100,000 line contrived text file containing 1M tabs and 1.8M spaces: $ wc -l foo 10 foo $ du -h foo 2.8Mfoo $ file foo foo: ASCII text $ time sh -c sed -e 's// /g' foo bar real0m2.479s user0m1.047s sys 0m0.105s $ md5 bar MD5 (bar) = f0187bcbc37cd6d84c6f5cadc6443843 $ time sh -c tr '\t' ' ' foo bar real0m0.261s user0m0.120s sys 0m0.026s $ md5 bar MD5 (bar) = f0187bcbc37cd6d84c6f5cadc6443843 $ time sh -c sed -e 'y// /' foo bar real0m0.261s user0m0.116s sys 0m0.087s $ md5 bar MD5 (bar) = f0187bcbc37cd6d84c6f5cadc6443843 -- Devin _ The information contained in this message is proprietary and/or confidential. If you are not the intended recipient, please: (i) delete the message and all copies; (ii) do not disclose, distribute or use the message in any manner; and (iii) notify the sender immediately. In addition, please be aware that any message addressed to our domain is subject to archiving and review by persons other than the intended recipient. Thank you. _ ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
RE: kwik way?
-Original Message- From: owner-freebsd-questi...@freebsd.org [mailto:owner-freebsd- questi...@freebsd.org] On Behalf Of Devin Teske Sent: Wednesday, May 18, 2011 11:19 AM To: 'Gary Kline'; 'FreeBSD Mailing List' Subject: RE: kwik way? -Original Message- From: owner-freebsd-questi...@freebsd.org [mailto:owner-freebsd- questi...@freebsd.org] On Behalf Of Gary Kline Sent: Wednesday, May 18, 2011 10:42 AM To: FreeBSD Mailing List Subject: kwik way? should i use tr or sed to turn \t into ? --i.e., tabs into spaces. Depends on how you do it in sed. The y/// operator is faster than s/// when transliterating a single character globally. If you use y/// instead of s///, then sed performance should be on-par with tr. Below are some performance metrics involving a 100,000 line contrived text file containing 1M tabs and 1.8M spaces: $ wc -l foo 10 foo $ du -h foo 2.8Mfoo $ file foo foo: ASCII text $ time sh -c sed -e 's// /g' foo bar real0m2.479s user0m1.047s sys 0m0.105s $ md5 bar MD5 (bar) = f0187bcbc37cd6d84c6f5cadc6443843 $ time sh -c tr '\t' ' ' foo bar real0m0.261s user0m0.120s sys 0m0.026s $ md5 bar MD5 (bar) = f0187bcbc37cd6d84c6f5cadc6443843 $ time sh -c sed -e 'y// /' foo bar real0m0.261s user0m0.116s sys 0m0.087s $ md5 bar MD5 (bar) = f0187bcbc37cd6d84c6f5cadc6443843 In case you were thinking of either awk or perl, I'd recommend against those given the following results: $ time sh -c awk '{gsub(/\t/,\ \);print}' foo bar real0m2.769s user0m1.498s sys 0m0.140s $ md5 bar MD5 (bar) = f0187bcbc37cd6d84c6f5cadc6443843 $ time sh -c perl -pe 'tr/\t/ /' foo bar real0m0.565s user0m0.277s sys 0m0.137s $ md5 bar MD5 (bar) = f0187bcbc37cd6d84c6f5cadc6443843 -- Devin _ The information contained in this message is proprietary and/or confidential. If you are not the intended recipient, please: (i) delete the message and all copies; (ii) do not disclose, distribute or use the message in any manner; and (iii) notify the sender immediately. In addition, please be aware that any message addressed to our domain is subject to archiving and review by persons other than the intended recipient. Thank you. _ ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org _ The information contained in this message is proprietary and/or confidential. If you are not the intended recipient, please: (i) delete the message and all copies; (ii) do not disclose, distribute or use the message in any manner; and (iii) notify the sender immediately. In addition, please be aware that any message addressed to our domain is subject to archiving and review by persons other than the intended recipient. Thank you. _ ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: Expanding tabs (was Re: kwik way?)
On Wed, May 18, 2011 at 01:09:36PM -0500, Dan Nelson wrote: Date: Wed, 18 May 2011 13:09:36 -0500 From: Dan Nelson dnel...@allantgroup.com Subject: Re: Expanding tabs (was Re: kwik way?) To: Gary Kline kl...@thought.org Cc: FreeBSD Mailing List freebsd-questions@freebsd.org In the last episode (May 18), Gary Kline said: should i use tr or sed to turn \t into ? --i.e., tabs into spaces. tr or expand (depending on whether you want to honor the intent of the tab or not). sed is overkill. yeah, agree. i grabbed an old `for k in *;do' script and used tr on 80+ files. [facing reality, i'm throwing in the towel on hacking. wanted something easy!] aapreciate it. -- Dan Nelson dnel...@allantgroup.com -- Gary Kline kl...@thought.org http://www.thought.org Public Service Unix Journey Toward the Dawn, E-Book: http://www.thought.org The 7.98a release of Jottings: http://jottings.thought.org ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
RE: kwik way?
On Wed, 18 May 2011, Devin Teske wrote: In case you were thinking of either awk or perl, I'd recommend against those given the following results: ... $ time sh -c perl -pe 'tr/\t/ /' foo bar real0m0.565s user0m0.277s sys 0m0.137s $ md5 bar MD5 (bar) = f0187bcbc37cd6d84c6f5cadc6443843 While Perl is a quarter of a second slower than best-case sed, it does offer the ability to directly understand \t (and \n, and lots of other escapes). ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org