Whitespace in SED

  • Permalink
  • submit to reddit
  • Email
  • Follow


I thought that \s was for whitespace, but the following does not seem to
work.  What am I missing?

s/^ \*\s*defin/ *  Defin/I

I'm trying to fix the following comment block in some code.  I want to force
two spaces between the asterisk and the initial "d", as well as convert the
"d" to uppercase.  The spacing could be a combination of spaces or tabs (ie.
whitespace).  The word "defining" could also be "define".

 *         defining buffer lengths


0
Reply fmankal (2) 1/8/2004 6:42:04 PM

See related articles to this posting



frank wrote:
> I thought that \s was for whitespace, but the following does not seem to
> work.  What am I missing?

The sed NG perhaps ;-) ?

> s/^ \*\s*defin/ *  Defin/I
> 
> I'm trying to fix the following comment block in some code.  I want to force
> two spaces between the asterisk and the initial "d", as well as convert the
> "d" to uppercase.  The spacing could be a combination of spaces or tabs (ie.
> whitespace).  The word "defining" could also be "define".
> 
>  *         defining buffer lengths
> 

This will work:

sed 's/^ \*[ 	]*[dD]efin/ *  Defin/'

where there's a single blank followed by a single tab within the first 
square brackets. For general white-space, look at the [:space:] 
construct in GNU sed.

	Ed.

0
Reply Ed 1/8/2004 7:02:26 PM

frank wrote:
> I thought that \s was for whitespace, but the following does not seem to
> work.  What am I missing?
> 
> s/^ \*\s*defin/ *  Defin/I
> 
> I'm trying to fix the following comment block in some code.  I want to force
> two spaces between the asterisk and the initial "d", as well as convert the
> "d" to uppercase.  The spacing could be a combination of spaces or tabs (ie.
> whitespace).  The word "defining" could also be "define".
> 
>  *         defining buffer lengths
> 
sed doesn't understand the \(letter) codes in regular expressions.
Use perl instead.

                Chris Mattern

0
Reply Chris 1/8/2004 8:35:07 PM
comp.lang.awk 3235 articles. 6 followers. Post

2 Replies
344 Views

Similar Articles

[PageSpeed] 28


  • Permalink
  • submit to reddit
  • Email
  • Follow


Reply:

Similar Artilces:

sed with whitespaces in pattern
To simplify a template for HTML files I need to remove redondant (i.e. billigual) expresions. Those phrases contain spaces and non ascii characters. How should I correct : sed 's=Zum Vergr��ern auf das Bild klicken -==g' to remove: Zum Vergr��ern auf das Bild klicken - Thank you! On Thu, 23 Nov 2006 22:24:47 -0500, Touche le mille <hamateur@honda.net> wrote: > To simplify a template for HTML files I need to remove redondant (i.e. > billigual) expresions. Those phrases contain spaces and non ascii > characters. > > How should I correct : > > sed &#...

Replacing whitespace, using bash script and sed
Hi All, I'm writing a script to start an application, which begins by doing this: #!/bin/sh BASEDIR=`dirname "$0"` BASEDIR=`echo $BASEDIR | sed -e 's/ /\\ /g'` echo Got $BASEDIR If I simulate what is going to happen (it's going to be started by a ..app) using the following from the Terminal, I get: sh /Users/neil/Development/planb/build/dist/mac/PlanB\ Console.app/Contents/MacOS/planbconsole Got /Users/neil/Development/planb/build/dist/mac/PlanB Console.app/Contents/MacOS Note that the Folder 'PlanB Console.app' has not been replaced with ...

SED
http://www.xtremesystems.org/forums/showthread.php?t=71226 Plans For The Future: In the near future, LCDs, CRTs, and Plasmas will be replaced by a new tech called SED. SED (Also called "Surface-conduction Electron-emitter Display") will offer the following specs: Response times of 1millisecond or EVEN LOWER!!! Contrast Ratio of up to 100,000:1 !!! Viewing angles of up to 160 degrees !!! Can scale up to 50” of HDTV viewable goodness !!! Blacks can go as low as 0.003 cd/m2 !!! Maximum Resolutions will be 1,920x1,080 !!! Other stuff about SED: -SED will also offer more vivid co...

sed
Hi *, is there easy way to install gnu sed (4.1.x) in home dir? I do not need man pages, or anything but sed. I tried installing it but as I'm not an Sun expert, I got an error .... checking for grep that handles long lines... checking for egrep... configure: error: no acceptable egrep could be found in $PATH But if I can avoid this, the install can't be in /usr dir, it has to be in my home... Nag, I know but can't help it :( Thanks, FrenKy Hi, forgot to mention before.. I found ftp://ftp.sunfreeware.com/pub/freeware/sparc/8/sed-4.1.1-sol8-sparc-local.gz this package, pro...

SED
Hi, I'm trying to write a script for the RISC OS port of sed, but I'm having trouble with two specific parts of the script (these problems aren't unique to the RISC OS port though, I've tested on Windows too - so I suspect my programming is at fault). The script should take an email message and turn it into just a string of words, all lower-case, with no punctuation or newlines etc. I've successfully got as far as removing punctuation and excess spaces, as well as replacing full stops with a null character (so words like ph.en.term.ine are left as phentermine) but I haven...

sed
Wallenda, a member of the famed "Flying Wallendas" family of aerialists, took a little more than 25 minutes to walk 1,800 feet from the U.S. side in the dark of night over treacherous waters and rocks in a nationally televised event. Arriving on the Canadian side, he hugged his family and greeted Canadian officials, who playfully requested the 33-year- old American's passport. Asked the purpose of his visit, Wallenda told the officials he had come to "inspire people." Richard Koumbos ...

sed
I'm puzzled (or maybe PCRE is what's confusing me); but for a minute consider the following: in> echo "[tab]foo" | sed 's/^[[:space:]]+//' out> [tab]foo in> echo "[tab]foo" | sed 's/^[[:space:]]*//' out> foo I thought that both the above commands should produce the same output? Secondly, I seem unable to use '\t' as a 'tab' although in a tcsh shell I can use ctrl-v + [tab]. I was under the impression that '\t' would work. My sed binary is built from FreeBSD 4.6.2 sources. Enlightenment is apprec...

How to Sed This?
Hello, I have a need to change two words at the same time and could not do it: change [connect system;] to [connect system/manager;] I do: sed 's/\connect system;\/\connect system/manager;\/' a1.sql > b1.sql and it does not work. Any comment are very appreciated (including awk, ...)!!! Ste Ste wrote: > Hello, > > I have a need to change two words at the same time and could not do it: > > change [connect system;] to [connect system/manager;] > > I do: > > sed 's/\connect system;\/\connect system/manager;\/' a1.sql > b1.sql &g...

sed ?
Hi I want to > sed ..... file1 file2 file3.... > another_file but I do not want to write file1 file2 file3, I want these file names to be listed in another file, FILE say. What I want to know is, how I can extract the file names from FILE and input them to sed, to obtain the result above, any suggestions? Thank you Douglas Douglas wrote: > Hi > > I want to > > >>sed ..... file1 file2 file3.... > another_file > > > but I do not want to write file1 file2 file3, I want these file names > to be listed in another file, FILE say. What I want...

replace gnu sed command ~ with sed command
Hi, I've written a little sed script which is working in my environment. But I tried it in another environment and there it didn't work because the ~ command was unknown there. Here the script: # beginning at line 3, remove every 8th line # beginning at line 4, remove every 8th line # beginning at line 5, remove every 8th line # beginning at line 6, remove every 8th line sed -e '3~8d 4~8d 5~8d 6~8d' file1.txt > file2.txt How could I replace this gnu sed command with a sed command which is valid in all environments? I tried different things...

whitespace
Is there an easy way in python to remove whitespace from a string? Quoting RR (rr84@cornell.edu): > Is there an easy way in python to remove whitespace from a string? Depending on what you mean by "remove whitespace": >>> mystring = " a b c d e f g " >>> mystring.strip() 'a b c d e f g' >>> import re >>> re.sub("\s+", "", mystring) 'abcdefg' > -- > http://mail.python.org/mailman/listinfo/python-list -- Geoff Gerrietts "Whenever people agree with me I alw...

Whitespace!!!!
I am trying: numberOfMangoes=9 b = strcat('I eat', ' ' , num2str(numberOfMangoes),' ', 'mangoes'); It prints: I eat9mangoes Why all the whitespaces are gone? scratching my head!! please help! regards Sam Samiran <samiran.dam@gmail.com> wrote in message <268b6007-f4bd-40ab-8fee-28df3eb7eeeb@k18g2000prf.googlegroups.com>... > I am trying: > > numberOfMangoes=9 > b = strcat('I eat', ' ' , num2str(numberOfMangoes),' ', 'mangoes'); > > It prints: > > I eat9mangoe...

whitespaces
Hello, is there a definition list for which characters match the RegExp /\s/ (and followed by all implementations)? Im currently looking for the non-breaking-space \u00A0. I found some scripts that use [\s\uA0] in RegExps, so I wondered whether this is really needed. A quick (and maybee dirty) test script: function test(x) { var r = []; for (var i=0; i<0x10000; i++) // 65536 if (x.exec(String.fromCharCode(i))) r.push(i); r = r.map(function(i){ return "\\u"+i.toString(16)+" bzw \\x"+i.toString(10) + ": '"+String.fromCharCode(i)+&quo...

Is this what sed is all about?
I have this tab delimited file in which I want to extract the fourth out of five columns. This fourth column contains filenames that I wish to move to another directory. What is the best way to achieve this? I am more concerned with extracting the fourth column. I am using /bin/ksh. Thanks, - 2004-06-30, 08:20(-07), D. Alvarado: > I have this tab delimited file in which I want to extract the fourth > out of five columns. This fourth column contains filenames that I > wish to move to another directory. What is the best way to achieve > this? I am more concerned with extract...

sed again
What if I have a more complex sed that has ' in it how can I put the sed into a bourne script becuase ' means something different in a bourne script? "Bob" <bob_then@yahoo.com.au> writes: > What if I have a more complex sed that has ' in it how can I put the sed > into a bourne script becuase ' means something different in a bourne script? Using an escape or a double-quote: [pjb@thalassa tmp]$ cat test Testy, isn't it. Testo It's Testy. Testa [pjb@thalassa tmp]$ sed -e /\'/s/Test/Grump/ < test Grumpy, isn't it. Testo It's Grumpy...

How to Sed This?
I have a need to change two words at the same time and could not do it: change [connect system;] to [connect system/manager;] I do: sed 's/\connect system;\/\connect system/manager;\/' a1.sql > b1.sql and it does not work. Any comment are very appreciated (including awk, ...)!!! Ste In article <LNnfb.12773$KR2.9122@newssvr31.news.prodigy.com>, Ste wrote: > I have a need to change two words at the same time and could not do it: > > change [connect system;] to [connect system/manager;] > > sed 's/\connect system;\/\connect system/manager;\/'...

sed: how do i do this?
First, I'm not sure sed is the best tool for the job, but I suspect it might be. Plus, I am trying to learn sed, so that'd be the preferred tool. I have a file and want to comment out part of it. I want specify a line (as a regular expression) and comment out every line after (and including) that line. The comment marker is 2 semi-colons at the beginning of each line. Thanks, Lowell Lowell wrote: > First, I'm not sure sed is the best tool for the job, but I suspect it > might be. Plus, I am trying to learn sed, so that'd be the preferred > tool. I have a fil...

sed with /
Hi Gurus I'm new to sed. How does one replace / with // for a string for example //filer/test/test2/test3/test4 to become ////filer//test/t/test2// test3//test4 ? I have tried a variety like TEMP_VAR=`/usr/bin/sed -e 's/\//K/g' //filer/test/test2/test3/test4 ` and I still can't get it right. I'm not sure how to escape /. Any help is appreciated. zw wrote: > Hi Gurus > > I'm new to sed. > How does one replace / with // for a string for example > //filer/test/test2/test3/test4 to become ////filer//test/t/test2// > test3//test4 ? Use another delimite...

With sed
$opt['tb'] = 'week1' \ The above line exists in a file From a script I want to use sed to catch this and replace it will a variable i or to be specific, I want to change the week1 to the value contained by $i On 2009-01-21, parag_paul@hotmail.com <parag_paul@hotmail.com> wrote: > > > $opt['tb'] = 'week1' > \ > The above line exists in a file > > From a script I want to use sed to catch this and replace it will a > variable i > > or to be specific, I want to change the week1 to the value contained > by $i > > sed ...

Structure using whitespace vs logical whitespace
I've been trying to search through the years of Python talk to find an answer to this, but my Googlefu is weak. In most languages, I'll do something like this xmlWriter.BeginElement("parent"); ----xmlWriter.BeginElement("child"); ----------xml.Writer.Characters("subtext"); ----xmlWriter.EndElement(); xmlWriter.EndElement(); Where the dashes are indentation (since some newsgroup handlers don't do tabs well). XML writing is just an example. In general, I'm using indentation to show logical flow through code. Python's choice to give semantic ...

SED or AWK (AIX sed or awk!) script help
Hello all. I have a big file that I need to delete a number of lines out of. I want to read the values that will determine deletion out of another file, because there are multiple. Can someone post an example of a sed or awk script to do this? (sumGirl) wrote: > Hello all. I have a big file that I need to delete a number of lines > out of. I want to read the values that will determine deletion out of > another file, because there are multiple. > > Can someone post an example of a sed or awk script to do this? Have you tried this? grep -vf smallfile bigfile > newfile No...

[SED] Searching and replacing for a string with a newline character with sed.
Hello everybody, I am sending this message both to comp.editors comp.unix.shell I think it is relevant to both groups; I hope it's OK. My question is this: When using the sed stream editor, I want to replace a regexp that contains a new line character with a specific string. It seams, however, that sed cannot look for a string with a newline in it. Here is a simple example: $ echo -e 'one\ntwo' | sed -e 's/one\ntwo/three/' Notice that echo -e 'one\ntwo' outputs: one two if sed can recognize the new line char, it should output: three But I get: one two wh...

two sed commands , want to reduce to one sed command
Hi, I have the following two sed commands that delete tabs in a file then deletes empty lines. I am having to use two seperated commands to do this including the move of the files. Is there a way I can reduce the two sed commands into one sed command to make it more efficent, or is there a way just to make the following commands more efficent. sed 's/ //g' /tmp/pat.txt > /tmp/pat.tmp mv /tmp/pat.tmp /tmp/pat.txt sed '/^$/d' /tmp/pat.txt >/tmp/pat.tmp mv /tmp/pat.tmp /tmp/pat.txt thanks pete. On comp.unix.shell, peter sands <peter_sa...

sed replace -- sed s/[^","" "]//g
Hi, Just want to replace "start with comer" or "any single space" with empty(delete) the command sed s/[^","" "]//g fail what is wrong? "start with comer" should be ^"," "any single space" should be " " [] equal to "or" anyone can give some hints? On Wed, 05 Jul 2006 17:26:05 +0800, SaltyBall wrote: > Just want to replace "start with comer" or "any single space" with > empty(delete) > > the command > sed s/[^","" "]//g > fail > > what...