Whitespace in SED

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
fmankal (2)
1/8/2004 6:42:04 PM
comp.lang.awk 3316 articles. 0 followers. Post Follow

2 Replies
451 Views

Similar Articles

[PageSpeed] 24

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
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
Chris
1/8/2004 8:35:07 PM
Reply:
Similar Artilces:

Convert complex sed statement into awk
Hello i hope someone can help me. I must express the following sed statement in awk statement sed -e "s/^\s*\(100002.2.2.1\)\s\(.*\):filter.cnf:\(.*\)/\1 \2\3 /" i have lines like 100002.2.2.1 :filter2.cnf::filter.cnf::filter3.cnf: there could be whitespaces between :: like 100002.2.2.1 :filter2.cnf: :filter.cnf: :filter3.cnf: and i want to delete the part ":filter.cnf:" so that i get 100002.2.2.1 :filter2.cnf::filter3.cnf: can you help me? I tried the following but it didnt work correct F_Filt_x=filter.cnf FILTER="100002.2.2.1" awk -v filter=&...

innerHTML text node whitespace question
simple question: I have a simple <dt>test text</dt> I get the innerHTML of that dt, and I try and append some text to it like so: dt = document.getElementsByTagName('dt')[0] var text = dt.innerHTML + 'new' in Firefox, I get "test textnew" and in IE I get "test text new" (with a space) If I have any Element Nodes within that dt or wrap that dt text node with a <span>, IE and firefox will append without a space. Obviously IE is adding whitespace to the text node where Firefox is not (and not doing that behavior when an Element Node exis...

whitespace normalization with \makeindex
The makeindex manual specifies that \index{a b} and \index{a b} will produce distinct index entries. I want to write a command that normalizes whitespace before passing it to index, so I wrote this: \documentclass{article} \newcount\wordcount % \newcommand\ndex[1]{\wordcount=0 \index{\ndeximpl#1 {\end} }} \def\ndeximpl#1 {% \ifx\end#1% \relax% \else% \advance\wordcount by 1 % \ifnum\wordcount>1 \ \fi% #1% \expandafter\ndeximpl% \fi% } \begin{document} hello\ndex{a and b} \end{document} I was hoping things would work well, but when I l...

sed add .0 decimal
I have several files that looks like this (actually a file of temperatures), 12:00 7.9 -8 5.0 16.3 12:10 8 -8.1 5.0 16 i need to reformat so that I always get a .0 where this is lacking, i.e. the output shall be 12:00 7.9 -8.0 5.0 16.3 12:10 8.0 -8.1 5.0 16.0 as seen the numbers can be negative. I have used a sed script looking like this (note that the spaces above are really tabs) #!/usr/bin/sed -f s/\t\(-*[0-9]\+\)$/\t\1.0/g s/\t\(-*[0-9]\+\)\t/\t\1.0\t/g But this does not fully work since it seems like even though the whole file is treated (by the g-option),...

Sed doc
hello ppl, please go to this link.. very useful for begginers.. http://www.grymoire.com/Unix/Sed.html On Aug 15, 11:32 am, Anup V <anupvargh...@gmail.com> wrote: > hello ppl, please go to this link.. very useful for begginers.. > [snipped url for another "I want all the webhits I can get" spammer] >From the html.. <body> <p><b>Thanks for making this the number #1 page in Google on 'sed'!</ b> and <p>Copyright 2001,2005,2007 Bruce Barnett and General Electric Company <p>All rights reserved <p>You are all...

Treetop Parser whitespace
I can't understand why the following test fails. Could you tell me why? Thanks, in advance. # in arithmetic.treetop grammar Arithmetic rule white_space [ \t\n\r]+ { def value text_value end } end end # in test_parser.rb require "rubygems" require "treetop" require "arithmetic" parser = ArithmeticParser.new p parser.parse(" \n\t\r") # the execution result $ ruby test_parser.rb nil -- Posted via http://www.ruby-forum.com/. Young tae Kim wrote: > I can't understand why the following test fails. &...

Trimming whitespaces
have a bit of c code that is ment to take a string (that may or may not have spaces before or after the string) i.e. " stuff ", and trims off the whitespace before and after. Code: char *trim (char *str, char ch) { char *first, *last; int count; /* Move first to the first character that isn't the same as ch */ for (first = str; *first == ch; first++); /* Move last to the null character. Thats the only way to know 100% we are * removing items from the end of the string */ for (last = first; *last != '\0'; last++); /* Ok now we backtrack until we find a character that isn...

sed substitution and escape characters.
Really ignorant sed user here, but I need to figure out a way to get this substation working properly... here's the call in my bash script: sed s/DEVICENAME/$DEVICE/g $objectsDir/volume.template > tmpFile023412a where the value of $DEVICE expands to something like: Other=SYSTEM:PATH=elk19e183:/work/foo/bar/data3 and when executed results in this: sed: Couldn't open file ork/foo/bar/data3/g so I'm assuming it has something to do with what sed is interpreting as control characters. How can I decorate the input string to be interpreted correctly? thanks in advance for any ...

FAQ Topic - How do I trim whitespace
----------------------------------------------------------------------- FAQ Topic - How do I trim whitespace - LTRIM/RTRIM/TRIM? ----------------------------------------------------------------------- Using Regular Expressions (JavaScript 1.2/JScript 4+) : String.prototype.LTrim=new Function("return this.replace(/^\\s+/,'')") String.prototype.RTrim=new Function("return this.replace(/\\s+$/,'')") String.prototype.Trim= new Function("return this.replace(/^\\s+|\\s+$/g,'')") or for all versions (trims characters ASCII&...

equivalent of grep -f in sed
Hi all, I want to implement in sed what the following command does grep -f file1 file2 what this basically does is, the contents of the file1 are taken as the pattern which has to be searched for in file2 i tried something like sed 's/file1/abc/g' <file2>file3 but instead of taking file1 as input it takes the literal string"file1" as input and seraches for that.kindly help me out here.thanks in advance naive_out_here <mailsuds@gmail.com> wrote: > > I want to implement in sed what the following command does > > grep -f file1 file2 > > wha...

SED: Insert Token at specific points
Hello I hada little problem we Data (CSV) files with following schema DATA "Karl" "2" "OLGA" "4" "5" "6" "TOTO" ... "70" DATA "1" "MEL" "URGA" "4" "SEPP" "6" "TOT" ... "70" And we want insert empty values at position 3 and 5 DATA "Karl" "2" "OLGA" "" "4" "5" "" "6" "TOTO" ... "70" DATA "1" "MEL" "URGA" ...

WXS: whiteSpace
I've got a few questions about the whiteSpace facet. 1. It seem to differ from the other factes, because it *modifies* the value instead of checking it. Is this correct? 2. Is this change kept after validation? Will a schema parser report the value according to the whiteSpace facet? Or is the modified value only for validation purposes? 3. Does whiteSpace have priority over the other facets? That is, is this element correct <a>1234</a> according to this simple type: <xsd:simpleType name="something"> <xsd:restriction base="xsd:string">...

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...

Sed : identify a pattern and append a word at the end of a line
Hello to all, On aix, I want to identify a term on a line in a file and then add a word at the end of the line identified. I do not want the word to be added when the line contains the symbol "#". original file 1 # 1 # 1 2 3 file processed 1 # 1;chmod 644 # 1 2 3 I could use the following command to carry out part of this function but it does not exclude the lines containing the symbol �#� $ sed '/1/ s/$/;chmod644/' filename 1# ;chmod 644 1 ;chmod 644 #1 ;chmod 644 2 3 Thank you very much for your help. excuse my English but I do not speak very well. Dantares wro...

\note command without extra whitespace?
I have a command \note defined as follows: % Make a note (i.e. an internal comment) % This note will only appear if \notestrue is set. \newcommand{\note}[1]{\ifnotes[#1]\else\ignore{#1}\fi} \newcommand{\ignore}[1]{} However, if I have some text that goes: Foo \note{test is a comment} bar. and \notesfalse, then there is more than just a single-space between "Foo" and "bar". Why is that? Is there a way I can write the command such that no extra white-space will be inserted, such that I don't have to write: Foo\note{test is a comment} bar. (which impedes the readabilit...

sed bug
While studying the source of sed I came across this: static int substitute(union reptr *ipc) { if(match(ipc->r1.re1, 0) == 0) return(0); numpass = 0; sflag = 0; /* Flags if any substitution was made */ dosub(ipc->r1.rhs, ipc->r1.gfl); ....... It seems like the sflag = 0 line should be removed (or moved to the first line of the function). According to sed(1) the branch should be taken if any substitution is done on the line (GNU sed behaves this way). It could be argued that the branch should be taken if the substitution immediately befo...

FAQ Topic - How do I trim whitespace
----------------------------------------------------------------------- FAQ Topic - How do I trim whitespace - trim/trimRight/trimLeft ----------------------------------------------------------------------- Using Regular Expressions (JavaScript 1.2/JScript 3+) : String.prototype.trimLeft = function() { return this.replace(/^\s+/,''); } String.prototype.trimRight = function() { return this.replace(/\s+$/,''); } String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g,''); ...

Question about the w command of sed
When I type sed -n '{N;w file1}' file2 I get sed: -e expression #1, char 0: Unmatched `{' The problem is that sed thinks that the } is part of the filename I want to write to. So how do I tell it this is not the case ? 2006-11-30, 16:11(-08), Spiros Bousbouras: > When I type > sed -n '{N;w file1}' file2 > I get > sed: -e expression #1, char 0: Unmatched `{' > > The problem is that sed thinks that the } is part > of the filename I want to write to. So how do I > tell it this is not the case ? [...] sed -ne '{N;w file1' -e '}' &...

Sed line deletion help
Hi Using GNU sed, how can I delete the line immediately _above_ the regexp? Deleting the line below the regexp is no problem eg: sed '/regexp/{n;d}' file I cannot figure this one out.. but surely it's possible? I'm looking for a "sed only" solution. Thanks Greg Greg Schafer wrote: > > Hi > > Using GNU sed, how can I delete the line immediately _above_ the regexp? Here is the awk way to do it... $ awk 'NR>1 && !/pattern/ {print s} {s=$0} END {print s}' > Deleting the line below the regexp is no problem eg: > > sed '/r...

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/awk insert
O sed gurus... I have a text file that contains an IP address. can be: 10.34.125.23 or 201.2.244.5 etc. I would like to insert \x00 before each character. e.g. so 10.34.125.23 becomes \x001\x000\x00.\x003\x004\x00.\x001\x002\x005\x00.\x002\x003 I have tried sed and awk but no luck.. :( Any suggestions will be most appreciated. bob_smithley@yahoo.com wrote: [...] > I have a text file that contains an IP address. > > can be: > > 10.34.125.23 > > or 201.2.244.5 > > etc. > > I would like to insert \x00 before each character. > > e.g. so 10.34...

"true whitespace" in tabular argument?
dear latex wizards--- Is there a style file that provides a "true whitespace" in tabular? by this I mean that \begin{tabular}{cc @{\qquad\qquad} cc} \multicolumn{2}{c}{A} & \multicolumn{2}{c}{B} \\ a & b &c & d \\ \end{tabular} knows that the 'A' should center over a and b, realizing that the space in the tabular is really supposed to be space. (otherwise, I now need \multicolumn{2}{c@{\qquad\qquad}}{A} .) I know I could insert an empty column and then add a '&' every column. I also know that I would not want this true white space in al...

Whitespace in Canonicalized XML
If I understand correctly, canonicalized XML is a simplified, or rather, "standardized" form of XML. It is in such a form such that two documents that are written in different ways, but contain the same information, will normalize towards one form. This standard form can then be used as the basis for encryption or digital verification (such as XML Digital Signature). If this is the case, then why is whitespace outside of any tags still preserved? (See Example 3.2 of the W3C Canonical XML Recommendation) Isn't that whitespace only useful for formatting purposes (ie. so that it...

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...

explode on whitespace
I'm assuming this is an easy question and I'm just missing something. I need to be able to explode a string on whitespace. The issue here is that I want to explode it such that all contiguous whitespace is one explode point. For example the following strings would all produce the same array of "words": This is a test. This is a test. This\tis a test. This\t \tis a test. Thoughts? liam193 said the following on 01/07/2005 14:00: > I'm assuming this is an easy question and I'm just missing something. > I need to be able to explode a string on whitespac...