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 > Spliiting a file by line delimiter
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Spliiting a file by line delimiter

Réponse
 
LinkBack Outils de la discussion
Vieux 10/12/2006, 12h02   #1
Polani
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Spliiting a file by line delimiter

Guys

I have an input text file which have ; character as seprator between
information segments. I want to split this file in such a way that i
can use ; as line delimiter .. which means that if i have an input file

---------------------------------------------------------------------------

5:172.16.22.70:3::AIX:5.2;2:172.16.22.35:3::AIX:5. 2;2:172.16.22.33:3::AIX:5.2;1:
172.16.22.31:3::AIX:5.2;3:172.16.22.51:3::AIX:5.2; 1:172.16.22.32:3::AIX:5.2;1:17
2.16.22.34:3::AIX:5.2;3:172.16.22.60:3::AIX:5.2;2: 172.16.22.41:3::AIX:5.2;2:172.
16.22.40:3::AIX:5.2;1:172.16.22.30:3::AIX:5.2;4:17 2.16.22.50:3::AIX:5.2;5:172.16
..22.71:3::AIX:5.2;4:172.16.22.61:3::AIX:5.2;
-------------------------------------------------------------------

I want to convert this input file something like that

---------------------------------------------------------
5:172.16.22.70:3::AIX:5.2;
2:172.16.22.35:3::AIX:5.2;
and so on

Hpw can i do that ? Thanks in advance for your suggestions

Regards

Polani

  Réponse avec citation
Vieux 10/12/2006, 12h47   #2
Bo Yang
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Spliiting a file by line delimiter

Polani :
> Guys
>
> I have an input text file which have ; character as seprator between
> information segments. I want to split this file in such a way that i
> can use ; as line delimiter .. which means that if i have an input file
>
> ---------------------------------------------------------------------------
>
> 5:172.16.22.70:3::AIX:5.2;2:172.16.22.35:3::AIX:5. 2;2:172.16.22.33:3::AIX:5.2;1:
> 172.16.22.31:3::AIX:5.2;3:172.16.22.51:3::AIX:5.2; 1:172.16.22.32:3::AIX:5.2;1:17
> 2.16.22.34:3::AIX:5.2;3:172.16.22.60:3::AIX:5.2;2: 172.16.22.41:3::AIX:5.2;2:172.
> 16.22.40:3::AIX:5.2;1:172.16.22.30:3::AIX:5.2;4:17 2.16.22.50:3::AIX:5.2;5:172.16
> ..22.71:3::AIX:5.2;4:172.16.22.61:3::AIX:5.2;
> -------------------------------------------------------------------
>
> I want to convert this input file something like that
>
> ---------------------------------------------------------
> 5:172.16.22.70:3::AIX:5.2;
> 2:172.16.22.35:3::AIX:5.2;
> and so on

There are too many ways to do this.
sed:

sed -n 's/;/;\n/gp'

>
> Hpw can i do that ? Thanks in advance for your suggestions
>
> Regards
>
> Polani
>

  Réponse avec citation
Vieux 10/12/2006, 23h03   #3
John W. Krahn
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Spliiting a file by line delimiter

Polani wrote:
>
> I have an input text file which have ; character as seprator between
> information segments. I want to split this file in such a way that i
> can use ; as line delimiter .. which means that if i have an input file
>
> ---------------------------------------------------------------------------
>
> 5:172.16.22.70:3::AIX:5.2;2:172.16.22.35:3::AIX:5. 2;2:172.16.22.33:3::AIX:5.2;1:
> 172.16.22.31:3::AIX:5.2;3:172.16.22.51:3::AIX:5.2; 1:172.16.22.32:3::AIX:5.2;1:17
> 2.16.22.34:3::AIX:5.2;3:172.16.22.60:3::AIX:5.2;2: 172.16.22.41:3::AIX:5.2;2:172.
> 16.22.40:3::AIX:5.2;1:172.16.22.30:3::AIX:5.2;4:17 2.16.22.50:3::AIX:5.2;5:172.16
> .22.71:3::AIX:5.2;4:172.16.22.61:3::AIX:5.2;
> -------------------------------------------------------------------
>
> I want to convert this input file something like that
>
> ---------------------------------------------------------
> 5:172.16.22.70:3::AIX:5.2;
> 2:172.16.22.35:3::AIX:5.2;
> and so on


$ echo
"5:172.16.22.70:3::AIX:5.2;2:172.16.22.35:3::AIX:5 .2;2:172.16.22.33:3::AIX:5.2;1:172.16.22.31:3::AIX :5.2;3:172.16.22.51:3::AIX:5.2;1:172.16.22.32:3::A IX:5.2;1:172.16.22.34:3::AIX:5.2;3:172.16.22.60:3: :AIX:5.2;2:172.16.22.41:3::AIX:5.2;2:172.16.22.40: 3::AIX:5.2;1:172.16.22.30:3::AIX:5.2;4:172.16.22.5 0:3::AIX:5.2;5:172.16.22.71:3::AIX:5.2;4:172.16.22 .61:3::AIX:5.2;"
| \
perl -073pe'$_.="\n"'
5:172.16.22.70:3::AIX:5.2;
2:172.16.22.35:3::AIX:5.2;
2:172.16.22.33:3::AIX:5.2;
1:172.16.22.31:3::AIX:5.2;
3:172.16.22.51:3::AIX:5.2;
1:172.16.22.32:3::AIX:5.2;
1:172.16.22.34:3::AIX:5.2;
3:172.16.22.60:3::AIX:5.2;
2:172.16.22.41:3::AIX:5.2;
2:172.16.22.40:3::AIX:5.2;
1:172.16.22.30:3::AIX:5.2;
4:172.16.22.50:3::AIX:5.2;
5:172.16.22.71:3::AIX:5.2;
4:172.16.22.61:3::AIX:5.2;





John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
  Réponse avec citation
Vieux 11/12/2006, 14h15   #4
Ed Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Spliiting a file by line delimiter

Polani wrote:

> Guys
>
> I have an input text file which have ; character as seprator between
> information segments. I want to split this file in such a way that i
> can use ; as line delimiter .. which means that if i have an input file
>
> ---------------------------------------------------------------------------
>
> 5:172.16.22.70:3::AIX:5.2;2:172.16.22.35:3::AIX:5. 2;2:172.16.22.33:3::AIX:5.2;1:
> 172.16.22.31:3::AIX:5.2;3:172.16.22.51:3::AIX:5.2; 1:172.16.22.32:3::AIX:5.2;1:17
> 2.16.22.34:3::AIX:5.2;3:172.16.22.60:3::AIX:5.2;2: 172.16.22.41:3::AIX:5.2;2:172.
> 16.22.40:3::AIX:5.2;1:172.16.22.30:3::AIX:5.2;4:17 2.16.22.50:3::AIX:5.2;5:172.16
> .22.71:3::AIX:5.2;4:172.16.22.61:3::AIX:5.2;
> -------------------------------------------------------------------
>
> I want to convert this input file something like that
>
> ---------------------------------------------------------
> 5:172.16.22.70:3::AIX:5.2;
> 2:172.16.22.35:3::AIX:5.2;
> and so on
>
> Hpw can i do that ? Thanks in advance for your suggestions
>
> Regards
>
> Polani
>


awk -v RS=";" -v ORS=";\n" '1' file

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 22h12.


Édité par : vBulletin® version 3.7.2
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
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,11384 seconds with 12 queries