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

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:

SED or AWK (AIX sed or awk!) script helpHello 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...

AWK or sed ?Hi There,
I need to do a couple of substitutions within several html files in one
single directory. The string:
http://www.autism.au/%7Ebanner/dunes/nice_place/
must be replaced by:
.../../../../
Does it need to be done with AWK or could sed do it? How to do it?
Thanks!
In article <1148311259.505147.224670@j73g2000cwa.googlegroups.com>,
<mikeomike@gmail.com> wrote:
>Hi There,
>
>I need to do a couple of substitutions within several html files in one
>single directory. The string:
>
>http://www.autism.au/%7Ebanner/dunes/nice_place/
>
>must be replace...

Awk or Sed ?Greetings,
What is the best way to do the following:
I have a text file and want lines between regular expressions 'hat
wear' and 'foot wear', but not including these lines.
With the lines returned I'd like to add a '#'in front of them.
Awk or sed ?
I do not wish to use Perl for this -- should be sed or awk.
I am thinking something like:
sed '/^hat wear/,/^foot wear/' inputfile
but I want to add a '#' to the lines between 'hat wear' and 'foot
wear' too.
Regards,
Patricia
On Fri, 7 Aug 2009 20:42:10 -0700 (PDT), Patricia Moor...

sed and awkI have a question about when to use sed or awk, and their
merits and defects.
Now, given a cpp file, which has two form of comments:
the line start with '//'
and the linexs between '/*' and '*/'
I want to get how many lines the comments are in the file.
Of course, I can use sed as following:
sed -n '/\/\*/,/\*\//p;/\/\//p'
to output all the commets. But if I want to output the
comments only, how to do? (this is not the main question,hehe)
Now, I want to change a method, still use sed, but this time
I want to do it another way:
for the situation '//'...

sed awkHi i have a question on stripping a string out of a file. I never did
anything with sed or awk. I was trying and couldn't really figure it
out.
My problem is as follows:
I have a file e.g.
<h3>
1.1 Hypertext
</h3>
<p>
Hypertext has been defined as "an approach to information
management in which data is stored in a network of nodes
connected by ............
</p>
I want to strip the 1.1. part after <h3>. Actually it is a more
general problem i have a lot of files with a heading and a number
after it. The only thi...

awk or sed??Hi all
I would like to know a awk or sed command that I will be able to
keep a word from a file text
exemple:
the informations are wrote line by line
dominique.dagenais
christian.belzil
alain.theroux
......
......
which command will be able to extrac only de third line
thank you
this will print the third line of your file.
awk ' NR == 3 { print $3 } '
or ....
you can use your own counter to print every third line.
Antonio Dell'elce
"Antonio Dell'elce" <antonio.dellelce@gmail.com> wrote:
[...]
> awk ' NR == 3 { print $3 } '
...

sed and awkI don't know sed awk beyond very basic (substitution in sed, printing
a column in awk), but was wondering if their matching mechanism has
the equivalents to shell's
${var%%pattern}
${var%pattern}
${var#pattern}
${var##pattern}
And by default, I believe sed and awk match the "longest" possible
match, usually from left, but from right if $ anchor is used.
2012-03-08 20:07:15 -0800, Lax:
> I don't know sed awk beyond very basic (substitution in sed, printing
> a column in awk), but was wondering if their matching mechanism has
> the equivalents to shell's
>...

sed or awk?I have a ridiculus ammount of files that needs to be sliced, here's a sample
Some title of a source
Author Source Publisher 2002
serial number Location
I need to split this into
Sometitle of a source
Author
Source Publisher
2002
serial number
Location
It would be easy if they only had one word text, however the title, author
and source publisher have several text. How would I implement this?
I thought about just getting the first line for the title, get the author
and detect 5 spaces and get the source publisher and look for the white
space between source publishe...

sed or awkHi,
i was looking for a shell utility using sed or awk that allows to switch
the case sensitive of the letters of a word. I mean, if i have a word
like "ShElLsCrIpT" the result of applying the shell script should be
"sHeLlScRiPt". The first idea was to read the word and cut letter by
letter and pass the letter to a function and check if the letter is
upper case or lower case and return the switched letter. Perhaps this is
too complex and before to do it i was wondering if somebody may know an
easier and simple way to do it.
Thanks a lot in advance,
Alex
2003/10/2...

Question to awk and sedHello,
I tried to get an output of all MAC-addresses by the following command
tcpdump | awk '/reply/ {print $6}' | sed 's/:/ /g'
There must be a problem with the output of awk and the pipe to sed for a
simple substitution as no address is printed. Is it possible to
integrate the subtitution to awk?
I appreciate any help you can give me.
T h o m a s B
--
"A patriot must always be ready to defend his country against his
government." Edward Abbey
Thomas Barth wrote, On 05/20/2005 10:16 AM:
> Hello,
> I tried to get an output of all MAC-addresses by the f...

awk sed question...Dear Friends,
I need a code that can replace a var_text in a line into xyz so I can
replace it later. The var_text can be a1, a2, a3, a4,
e.g.
stainless mud pan,construction,,,4,4,1196924152,,a2,,
jonaharah@gmail.com wrote:
>
> I need a code that can replace a var_text in a line into xyz so I can
> replace it later. The var_text can be a1, a2, a3, a4,
>
>
> e.g.
>
> stainless mud pan,construction,,,4,4,1196924152,,a2,,
sed "s/a[1-4]/xyz/"
--
Best regards | Be nice to America or they'll bring democracy to
Cyrus | your count...

sed and awk usage?Hi, I have to re-write some data, and hope to find some help using sed or
awk to do so.
The lines are similar to:
2007-01-22,1.55,1.75,1.55,1.61,122100,1.61
and need to be in form:
22-Jan-07,1.55,1.75,1.55,1.61,122100,1.61
All days, months and years need to be re-written in first csv field.
Any help, please? I don't know sed or awk well enough to make much progress,
thanks.
On Tue, 23 Jan 2007 19:33:46 -0800, grus wrote:
> Hi, I have to re-write some data, and hope to find some help using sed or
> awk to do so.
>
> The lines are similar to:
> 2007-01-22,1.55,1.75,1....

Help with sed/awk ?Hello all,
When I dump (parts) of a postgres database into a textfile I get it in
the following format (each users data on three rows). The reason for
it is probably that the last field contain cr/lf characters.
-------------------------------------------------------
45|User1|Lastname||555-12345||Fakestreet 1
ODF4/145:146
dBm: 13.3
46|User2|Lastname||555-12346||Fakestreet 2
ODF2/43:44
dBm: 13.42
47|User3|Lastname||555-12347||Fakestreet 3
ODF5/7:8
dBm: 13.36
-------------------------------------------------------
What I want but haven't been able to achieve is t...