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 > how to delete selected columns?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

how to delete selected columns?

Réponse
 
LinkBack Outils de la discussion
Vieux 04/12/2006, 03h59   #1
CU.CISL@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut how to delete selected columns?

Hi,

Let's say I have a text file look like this:

1,0,1,1,0
0,1,1,0,0
1,1,1,0,0
1,0,0,1,1

I just wanna delete first 4 columns(leave 5-9 columns) to get:

1,1,0
1,0,0
1,0,0
0,1,1

Which command should I choose? colrm/tr/sed/awk/cut? It seems that
sed/awk take that file as a four row one column file. And I can't use
cut -c5-9 <infile> > <outfile>, since the real problem involves other
issue.

Thanks a lot!!
-S

  Réponse avec citation
Vieux 04/12/2006, 04h24   #2
Chris F.A. Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how to delete selected columns?

On 2006-12-04, CU.CISL@gmail.com wrote:
> Hi,
>
> Let's say I have a text file look like this:
>
> 1,0,1,1,0
> 0,1,1,0,0
> 1,1,1,0,0
> 1,0,0,1,1
>
> I just wanna delete first 4 columns(leave 5-9 columns) to get:
>
> 1,1,0
> 1,0,0
> 1,0,0
> 0,1,1
>
> Which command should I choose? colrm/tr/sed/awk/cut? It seems that
> sed/awk take that file as a four row one column file. And I can't use
> cut -c5-9 <infile> > <outfile>, since the real problem involves other
> issue.


What issue is that? What's wrong with cut -c5-9? Or:

cut -c5-

Or:

cut -d, -f3-


--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
  Réponse avec citation
Vieux 04/12/2006, 04h37   #3
Ed Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how to delete selected columns?

CU.CISL@gmail.com wrote:

> Hi,
>
> Let's say I have a text file look like this:
>
> 1,0,1,1,0
> 0,1,1,0,0
> 1,1,1,0,0
> 1,0,0,1,1
>
> I just wanna delete first 4 columns(leave 5-9 columns) to get:
>
> 1,1,0
> 1,0,0
> 1,0,0
> 0,1,1
>
> Which command should I choose? colrm/tr/sed/awk/cut? It seems that
> sed/awk take that file as a four row one column file. And I can't use
> cut -c5-9 <infile> > <outfile>, since the real problem involves other
> issue.
>
> Thanks a lot!!
> -S
>


Eihter of these may do what you want:

awk 'BEGIN{FS=OFS=","}{print $3,$4,$5}' file
sed 's/....//' file
cut -d, -f3-5

It's hard to say given there's some unspecified "other issue"...

Regards,

Ed.
  Réponse avec citation
Vieux 04/12/2006, 13h33   #4
Daniel
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how to delete selected columns?

Thanks Ed and Chris! That me a lot!


Ed Morton wrote:
> CU.CISL@gmail.com wrote:
>
> > Hi,
> >
> > Let's say I have a text file look like this:
> >
> > 1,0,1,1,0
> > 0,1,1,0,0
> > 1,1,1,0,0
> > 1,0,0,1,1
> >
> > I just wanna delete first 4 columns(leave 5-9 columns) to get:
> >
> > 1,1,0
> > 1,0,0
> > 1,0,0
> > 0,1,1
> >
> > Which command should I choose? colrm/tr/sed/awk/cut? It seems that
> > sed/awk take that file as a four row one column file. And I can't use
> > cut -c5-9 <infile> > <outfile>, since the real problem involves other
> > issue.
> >
> > Thanks a lot!!
> > -S
> >

>
> Eihter of these may do what you want:
>
> awk 'BEGIN{FS=OFS=","}{print $3,$4,$5}' file
> sed 's/....//' file
> cut -d, -f3-5
>
> It's hard to say given there's some unspecified "other issue"...
>
> Regards,
>
> Ed.


  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 05h23.


É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,12262 seconds with 12 queries