Article View: comp.unix.shell
Article #4103Re: sed/awk/perl: How to replace all spaces each with an underscore that occur before a specific string ?
From: w_a_x_man
Date: Sat, 22 Aug 2009 18:24
Date: Sat, 22 Aug 2009 18:24
21 lines
2012 bytes
2012 bytes
On Aug 22, 1:11 pm, bolega <gnuist...@gmail.com> wrote:
> sed/awk/perl:
>
> How to replace all spaces each with an underscore that occur before a
> specific string ?
>
> I really prefer a sed one liner.
>
> Example
> Input : This is my book. It is too thick to read. The author gets
> little royalty but the publisher makes a lot.
> Output: This_is_my_book._It_is_too__thick_to read. The author gets
> little royalty but the publisher makes a lot.
>
> We replaced all the spaces with underscores before the first occurence
> of the string "to ".
>
> Thanks
> Gnuist
awk 'BEGIN{FS=OFS="to "}{gsub(/ /,"_",$1);print}' myfile
Technical Details
Message-ID:
<1bc82397-1e91-4055-879a-c178534e1c17@z24g2000yqb.googlegroups.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!postnews.google.com!z24g2000yqb.googlegroups.com!not-for-mailReferences:
<1380cb14-6462-4585-b2d1-c59c99ff9b56@b15g2000yqd.googlegroups.com>Show Full Headers
Complete Article Headers
X-Google-Thread: bd748d9281,9ccd2e7066d84876 X-Google-Attributes: gidbd748d9281,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: arc1-ca.pugleaf.net!g2news2.google.com!postnews.google.com!z24g2000yqb.googlegroups.com!not-for-mail From: w_a_x_man <w_a_x_man@yahoo.com> Newsgroups: comp.unix.shell,gnu.emacs.help,comp.lang.python,comp.lang.lisp,comp.lang.scheme Subject: Re: sed/awk/perl: How to replace all spaces each with an underscore that occur before a specific string ? Date: Sat, 22 Aug 2009 11:24:56 -0700 (PDT) Organization: http://groups.google.com Lines: 21 Message-ID: <1bc82397-1e91-4055-879a-c178534e1c17@z24g2000yqb.googlegroups.com> References: <1380cb14-6462-4585-b2d1-c59c99ff9b56@b15g2000yqd.googlegroups.com> NNTP-Posting-Host: 208.100.224.129 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1250965496 8748 127.0.0.1 (22 Aug 2009 18:24:56 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 22 Aug 2009 18:24:56 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: z24g2000yqb.googlegroups.com; posting-host=208.100.224.129; posting-account=vf5QpQoAAADgh9WOa2uZtoS1yoyJdEBw User-Agent: G2/1.0 X-HTTP-UserAgent: Opera/9.64 (Windows 98; U; en) Presto/2.1.1,gzip(gfe),gzip(gfe)