|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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 :-) |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
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 |
|
![]() |
| Outils de la discussion | |
|
|