PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > sed vs. vim
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

sed vs. vim

Réponse
 
LinkBack Outils de la discussion
Vieux 27/07/2007, 16h38   #1
wexfordpress
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut sed vs. vim

in vim the left end of a line can notated with a ^ and the right end
with a $. Is this also true for current versions of sed? If not, what
is the notation to select lines that begin with a "<" for example but
exclude those where a "<" occurs elsewhere in the line?

My only sed manual is from Coherent and that is pretty old :<)

I use Slackware 12 at present.
John Culleton

  Réponse avec citation
Vieux 27/07/2007, 16h50   #2
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: sed vs. vim

2007-07-27, 08:38(-07), wexfordpress:
> in vim the left end of a line can notated with a ^ and the right end
> with a $. Is this also true for current versions of sed? If not, what
> is the notation to select lines that begin with a "<" for example but
> exclude those where a "<" occurs elsewhere in the line?
>
> My only sed manual is from Coherent and that is pretty old :<)

[...]

Have you tried man sed?

^ and $ are standard regular expression operators (both in basic
and extended regexps). Every tool that uses regular expressions
will recognise them. Moreover, both vi and sed are based on ed,
so share that common part.

sed '/^foo/!d'

will delete every line but those that start with foo. That's the
same as grep '^foo' or :v/^foo/d in vim or awk '/^foo/'.

sed -n '/^</{/>/!p;}'

will print lines that start with "<" and don't contain ">".

You can also write it:

sed '/^</!d;/>/d'

You can also write it:

awk '/^</ && !/>/'

or

grep '^<' | grep -v '>'

--
Stéphane
  Réponse avec citation
Vieux 28/07/2007, 13h50   #3
wexfordpress
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: sed vs. vim

On Jul 27, 11:50 am, Stephane CHAZELAS <this.addr...@is.invalid>
wrote:
> 2007-07-27, 08:38(-07), wexfordpress:> in vim the left end of a line can notated with a ^ and the right end
> > with a $. Is this also true for current versions of sed? If not, what
> > is the notation to select lines that begin with a "<" for example but
> > exclude those where a "<" occurs elsewhere in the line?

>
> > My only sed manual is from Coherent and that is pretty old :<)

>
> [...]
>
> Have you tried man sed?
>
> ^ and $ are standard regular expression operators (both in basic
> and extended regexps). Every tool that uses regular expressions
> will recognise them. Moreover, both vi and sed are based on ed,
> so share that common part.
>
> sed '/^foo/!d'
>
> will delete every line but those that start with foo. That's the
> same as grep '^foo' or :v/^foo/d in vim or awk '/^foo/'.
>
> sed -n '/^</{/>/!p;}'
>
> will print lines that start with "<" and don't contain ">".
>
> You can also write it:
>
> sed '/^</!d;/>/d'
>
> You can also write it:
>
> awk '/^</ && !/>/'
>
> or
>
> grep '^<' | grep -v '>'
>
> --
> Stéphane


Very educational. Thanks. The man page for sed does not mention ^
explicitly.

I think I will lurk in this group for a while and get an education.

John Culleton

  Réponse avec citation
Vieux 28/07/2007, 15h29   #4
loki harfagr
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: sed vs. vim

On Sat, 28 Jul 2007 05:50:55 -0700, wexfordpress wrote:

> On Jul 27, 11:50 am, Stephane CHAZELAS <this.addr...@is.invalid> wrote:
>> 2007-07-27, 08:38(-07), wexfordpress:> in vim the left end of a line
>> can notated with a ^ and the right end
>> > with a $. Is this also true for current versions of sed? If not,
>> > what is the notation to select lines that begin with a "<" for
>> > example but exclude those where a "<" occurs elsewhere in the line?

>>
>> > My only sed manual is from Coherent and that is pretty old :<)

>>
>> [...]
>>
>> Have you tried man sed?
>>
>> ^ and $ are standard regular expression operators (both in basic and
>> extended regexps). Every tool that uses regular expressions will
>> recognise them. Moreover, both vi and sed are based on ed, so share
>> that common part.
>>
>> sed '/^foo/!d'
>>
>> will delete every line but those that start with foo. That's the same
>> as grep '^foo' or :v/^foo/d in vim or awk '/^foo/'.
>>
>> sed -n '/^</{/>/!p;}'
>>
>> will print lines that start with "<" and don't contain ">".
>>
>> You can also write it:
>>
>> sed '/^</!d;/>/d'
>>
>> You can also write it:
>>
>> awk '/^</ && !/>/'
>>
>> or
>>
>> grep '^<' | grep -v '>'
>>
>> --
>> Stéphane

>
> Very educational. Thanks. The man page for sed does not mention ^
> explicitly.


That's right, in Slackware (and most Linux) the simple man pages are
very concise, and for 'sed' they mostly concentrate on the commands to
control the line selection, though they also refer to the regexp which
is the part relative to flow contol and substitution.

More, in Slackware you'll find the full story and some useful examples
for 'sed' in the info page, so instead of
# man sed
you may like to read:
# info sed

>
> I think I will lurk in this group for a while and get an education.


That's certainly a good place to read and the flames are rare
and well educated :-)
  Réponse avec citation
Vieux 29/07/2007, 03h09   #5
Carl Lowenstein
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: sed vs. vim

In article <1185627055.454534.121850@b79g2000hse.googlegroups .com>,
wexfordpress <john@wexfordpress.com> wrote:
>On Jul 27, 11:50 am, Stephane CHAZELAS <this.addr...@is.invalid>
>wrote:
>> 2007-07-27, 08:38(-07), wexfordpress:> in vim the left end of a line

>can notated with a ^ and the right end
>> > with a $. Is this also true for current versions of sed? If not, what
>> > is the notation to select lines that begin with a "<" for example but
>> > exclude those where a "<" occurs elsewhere in the line?

>>
>> > My only sed manual is from Coherent and that is pretty old :<)

>>
>> [...]
>>
>> Have you tried man sed?
>>

Discussion of elementary regular expressions snipped. Can be found
lots of other places.
>
>Very educational. Thanks. The man page for sed does not mention ^
>explicitly.


The man page for sed references the man page for ed, where you can
find a fairly complete discussion of regular expressions. As far
as having pretty old man pages, you should realize that the use of
regular expressions in ed dates back as far as Sixth Edition Unix (1973)
or further. That's 34 years, by my calculation.

carl

--
carl lowenstein marine physical lab, u.c. san diego
clowenstein@ucsd.edu
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 13h41.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,75729 seconds with 13 queries