From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: bolega Newsgroups: gmane.emacs.help Subject: sed/awk/perl: How to replace all spaces each with an underscore that occur before a specific string ? Date: Sat, 22 Aug 2009 11:11:32 -0700 (PDT) Organization: http://groups.google.com Message-ID: <1380cb14-6462-4585-b2d1-c59c99ff9b56__5664.43046923286$1250966529$gmane$org@b15g2000yqd.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1250966529 23786 80.91.229.12 (22 Aug 2009 18:42:09 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 22 Aug 2009 18:42:09 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Aug 22 20:42:02 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MevXM-0002E0-Tg for geh-help-gnu-emacs@m.gmane.org; Sat, 22 Aug 2009 20:42:01 +0200 Original-Received: from localhost ([127.0.0.1]:59608 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MevXL-0004lG-Ts for geh-help-gnu-emacs@m.gmane.org; Sat, 22 Aug 2009 14:41:59 -0400 Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!b15g2000yqd.googlegroups.com!not-for-mail Original-Newsgroups: comp.unix.shell, gnu.emacs.help, comp.lang.python, comp.lang.lisp, comp.lang.scheme Original-Lines: 21 Original-NNTP-Posting-Host: 75.32.191.209 Original-X-Trace: posting.google.com 1250964692 17749 127.0.0.1 (22 Aug 2009 18:11:32 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Sat, 22 Aug 2009 18:11:32 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: b15g2000yqd.googlegroups.com; posting-host=75.32.191.209; posting-account=REkl4woAAABFXaU7nL79XtGpnmNCQ415 User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30),gzip(gfe),gzip(gfe) Original-Xref: news.stanford.edu comp.unix.shell:229312 gnu.emacs.help:172267 comp.lang.python:606039 comp.lang.lisp:274221 comp.lang.scheme:82282 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:67423 Archived-At: 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