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 > IS this possible
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

IS this possible

Réponse
 
LinkBack Outils de la discussion
Vieux 07/09/2007, 19h33   #1
chani
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut IS this possible

Dear all,

I am new to sed. Assume I have a file which contain follwings


1. A.B.C des a/03/111
2. X.Y.Z pqr a/04/114

if i use the command

$ sed s/'a\/0[0-9]\/[0-9][0-9][0-9]'//g t

the last column will be deleted. & output will be

1. A.B.C des
2. X.Y.Z pqr

But I want the inverse of this. That means deleting other column &
extract last column
Is it possible with sed.

I know it can be done with cut.
But in my actual file data contain like this.



1. A.B.C des a/03/111
2. a/04/114 X.Y.Z pqr

So what i want is to keep matching pattern & deleting remaining.
Can you please give me a .


Thank you !!!

  Réponse avec citation
Vieux 07/09/2007, 20h42   #2
Ed Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: IS this possible

chani wrote:

> Dear all,
>
> I am new to sed. Assume I have a file which contain follwings
>
>
> 1. A.B.C des a/03/111
> 2. X.Y.Z pqr a/04/114
>
> if i use the command
>
> $ sed s/'a\/0[0-9]\/[0-9][0-9][0-9]'//g t
>
> the last column will be deleted. & output will be
>
> 1. A.B.C des
> 2. X.Y.Z pqr


It doesn't have to be that complicated. Look:

$ cat file
1. A.B.C des a/03/111
2. X.Y.Z pqr a/04/114
$ sed 's/[^ ]*$//' file
1. A.B.C des
2. X.Y.Z pqr

or 's/ *[^ ]*$//' if you want to get rid of the trailing spaces too.

> But I want the inverse of this. That means deleting other column &
> extract last column
> Is it possible with sed.



Well, yes:

$ sed 's/.* //' file
a/03/111
a/04/114

> I know it can be done with cut.
> But in my actual file data contain like this.
>
>
>
> 1. A.B.C des a/03/111
> 2. a/04/114 X.Y.Z pqr
>
> So what i want is to keep matching pattern & deleting remaining.
> Can you please give me a .


You don't show what you want your output to be so it's hard to guess
what you want, but in general to match on a pattern and only print that
you'd do:

sed 's/.*\(pattern\).*/\\1/' file

You may want to post some better sample input, expected output and
explanation.

Ed.

  Réponse avec citation
Vieux 07/09/2007, 20h44   #3
John L
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: IS this possible


"chani" <chanakam2000@gmail.com> wrote in message news:1189189997.794622.125040@r29g2000hsg.googlegr oups.com...
> But in my actual file data contain like this.
>
>
>
> 1. A.B.C des a/03/111
> 2. a/04/114 X.Y.Z pqr
>
> So what i want is to keep matching pattern & deleting remaining.
>


Yes. Use tagged regular expressions.

First, since there are /s in the expression, let's use : as delimiter.
Let us also move the quotes to surround the whole expression.

sed 's:.*\(a/0[0-9]/[0-9][0-9][0-9]\).*:\1:'

The \(...\) surround the regular expression you are interested in,
and the \1 replaces whatever was matched with the 1st matched
expression (likewise \2, \3 ... \9 if there are more than one).

Or, using /s which need to be escaped:
sed 's/.*\(a\/0[0-9]\/[0-9][0-9][0-9]\).*/\1/'

You might not need the first .* -- it depends whether the line
numbers are part of the file.

--
John.


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


É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,08451 seconds with 11 queries