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