Prev: Example of kill -9 erasing and/or corrupting a (temporary) file?
Next: wget -r (recursive) failing to back up a site
From: David Kirkby on 7 Jun 2010 19:45 On Jun 7, 8:38 pm, Harry <harryooopot...(a)hotmail.com> wrote: > On Jun 7, 12:47 am, David Kirkby <drkir...(a)gmail.com> wrote: > > > I have a list of files > [...] > > and would like to remove the hyphen and all characters after them. > > [...] > > sed -e 's/-.*//' Thank you - that is just what I wanted. Dave
From: Janis Papanagnou on 7 Jun 2010 19:51 David Kirkby wrote: > On Jun 7, 10:42 am, Andrew McDermott <a.p.mcderm...(a)NOSPAM-rl.ac.uk> > wrote: >> David Kirkby wrote: >>> I think 'sed' is the tool for this, though I may be wrong. >>> I have a list of files >> Do you mean you have a set of files in a directory >> >> >> >> >> >>> atlas-3.8.3.p12.spkg >>> blas-20070724.spkg >>> boehm_gc-7.1.p5.spkg >>> boost-cropped-1.34.1.spkg > >>> and would like to remove the hyphen and all characters after them. So >>> I get >> and you want to rename them? > > No, I do not want to rename them. I just want a list, without the > version numbers. (These are mathematical packages with various version > numbers. I just want a list of the packages. > Then pipe your ls output[*] into the sed command that pk suggested. [*] Of course you don't need ls(1), you can as well use printf (which is often a shell builtin) and avoid the extra process. Janis
From: Janis Papanagnou on 7 Jun 2010 19:54 David Kirkby wrote: > On Jun 7, 8:38 pm, Harry <harryooopot...(a)hotmail.com> wrote: >> On Jun 7, 12:47 am, David Kirkby <drkir...(a)gmail.com> wrote: >> >>> I have a list of files >> [...] >>> and would like to remove the hyphen and all characters after them. >> [...] >> >> sed -e 's/-.*//' > > Thank you - that is just what I wanted. No, it's not. See what you asked for and look at the /boost/ entry. Instead take pk's suggestion. (Or are there new requirements now?) Janis > > Dave
From: Fostytou - AKA FrostFace on 21 Jun 2010 16:03 On Jun 7, 2:47 am, David Kirkby <drkir...(a)gmail.com> wrote: > I think 'sed' is the tool for this, though I may be wrong. > > I have a list of files > > atlas-3.8.3.p12.spkg > blas-20070724.spkg > boehm_gc-7.1.p5.spkg > boost-cropped-1.34.1.spkg > cddlib-094f.p6.spkg > cephes-2.8.spkg > cliquer-1.2.p5.spkg > conway_polynomials-0.2.spkg > cvxopt-0.9.p8.spkg > cython-0.12.1.spkg > deps > docutils-0.5.p0.spkg > ecl-10.2.1.spkg > eclib-20080310.p10.spkg > > and would like to remove the hyphen and all characters after them. So > I get > > atlas > blas > boehm_gc > boost-cropped > cddlib > cephes > cliquer > conway_polynomials > > etc > > What's the best way to do this? > > I note 'deps' has no hypen, but I think that is the only such case and > can be handled manually if need be. There's about 100 of these, so > whilst doing them manually is not impossible, it's a bit tedious. > > Note I actually want to remove the hyphen, so the subject line is > slightly inaccurate, but any attempt I could think of to rewrite the > subject line in a more accurate form just got too wordy. In any case, > I know how to remove a hyphen easily. > > Dave You could also use awk pretty efficiently: awk 'BEGIN {FS=OFS="-"} {print $1}' [YOURFILELIST]
From: Ed Morton on 21 Jun 2010 16:54 On Jun 21, 3:03 pm, Fostytou - AKA FrostFace <fosty...(a)gmail.com> wrote: > On Jun 7, 2:47 am, David Kirkby <drkir...(a)gmail.com> wrote: > > > > > > > I think 'sed' is the tool for this, though I may be wrong. > > > I have a list of files > > > atlas-3.8.3.p12.spkg > > blas-20070724.spkg > > boehm_gc-7.1.p5.spkg > > boost-cropped-1.34.1.spkg > > cddlib-094f.p6.spkg > > cephes-2.8.spkg > > cliquer-1.2.p5.spkg > > conway_polynomials-0.2.spkg > > cvxopt-0.9.p8.spkg > > cython-0.12.1.spkg > > deps > > docutils-0.5.p0.spkg > > ecl-10.2.1.spkg > > eclib-20080310.p10.spkg > > > and would like to remove the hyphen and all characters after them. So > > I get > > > atlas > > blas > > boehm_gc > > boost-cropped > > cddlib > > cephes > > cliquer > > conway_polynomials > > > etc > > > What's the best way to do this? > > > I note 'deps' has no hypen, but I think that is the only such case and > > can be handled manually if need be. There's about 100 of these, so > > whilst doing them manually is not impossible, it's a bit tedious. > > > Note I actually want to remove the hyphen, so the subject line is > > slightly inaccurate, but any attempt I could think of to rewrite the > > subject line in a more accurate form just got too wordy. In any case, > > I know how to remove a hyphen easily. > > > Dave > > You could also use awk pretty efficiently: > > awk 'BEGIN {FS=OFS="-"} {print $1}' [YOURFILELIST]- Hide quoted text - > > - Show quoted text - No need to assign OFS if you're only printing 1 field: awk -F- '{print $1}' files Ed.
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 Prev: Example of kill -9 erasing and/or corrupting a (temporary) file? Next: wget -r (recursive) failing to back up a site |