Newsgroups: intel.comp.unix,comp.unix.admin,comp.unix.questions,fj.questions.unix
Path: galaxy.trc.rwcp.or.jp!news.trc!imnet3!news.imnet.ad.jp!news.join.ad.jp!newsfeed.mathworks.com!news-out.cwix.com!newsfeed.cwix.com!news.umass.edu!world!demas
From: demas@world.std.com (Charles Demas) 
Subject: Re: sed/ed question: how to replace the 4th string in a line
Message-ID: <FqC9Fr.1K3@world.std.com>
Sender: demas@world.std.com
Date: Tue, 22 Feb 2000 15:52:39 GMT
References: <38b25b13.175503125@ilnews.iil.intel.com>
Organization: Pot Kettle Black
Lines: 37
Xref: galaxy.trc.rwcp.or.jp fj.questions.unix:10263
X-originally-archived-at: http://galaxy.rwcp.or.jp/text/cgi-bin/newsarticle2?ng=fj.questions.unix&nb=10263&hd=a
X-reformat-date: Mon, 18 Oct 2004 15:18:22 +0900
X-reformat-comment: Tabs were expanded into 4 column tabstops by the Galaxy's archiver. See http://katsu.watanabe.name/ancientfj/galaxy-format.html for more info.

In article <38b25b13.175503125@ilnews.iil.intel.com>,
 <rbarakX@iil.intel.com> wrote:
>Hi Guys,
>
>I was trying to solve the following problem with sed/ed, but failed.
>Could anyone help ?
>
>The problem:
>
>Given the following line:
>
>aaaaaaa bbbbbb cccccc dddddd eeeeeee
>
>how to replace the fourth string with another string zzzzzzz
>
>Note: the strings are random in both their length and value (meaning
>that s/dddddd/zzzzzzz/ is not the solution :-), and - the number of
>strings in the line is unknown (but less than - say - 20).

If your version of sed recognizes \< and \> as the beginning and 
end of a word, you might do this:

sed -e 's/\<[^ ][^ ]*\>/zzzzzzzz/4' infile

or you might do:

sed -e 's/ [^ ][^ ]*/ zzzzzzz/3' infile


Chuck Demas
Needham, Mass.

-- 
  Eat Healthy    |   _ _   | Nothing would be done at all,
  Stay Fit       |   @ @   | If a man waited to do it so well,
  Die Anyway     |    v    | That no one could find fault with it.
  demas@tiac.net |  \___/  | http://www.tiac.net/users/demas
