#### 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 3309 articles. 6 followers.

2 Replies
437 Views

Similar Articles

[PageSpeed] 26

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

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.

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