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 > Merge all Lines into one?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Merge all Lines into one?

Réponse
 
LinkBack Outils de la discussion
Vieux 01/12/2006, 23h30   #1
ryandle@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Merge all Lines into one?

Hello all.

Im currently trying to take a file with a series of numbers on each
line and merge them into one line. I also would like to insert a "+"
between each one so that i can run binary calc on the file and add them
all together. here is an example of what im trying to do.


#file 1
45.34
-234.33
96
54
-4.33

# i want to turn a file like that into a file with one line:

45.34+-234.33+96+54+-4.33

Is this possile? I am scripting in CSH. This is part of a project, so
i have to use the CSH shell. Any and all ideas would be very ful!!
If this is not possible, is there another way to add every number in
that file? The file only consists of numbers, one per line. Thanks in
advance!!

  Réponse avec citation
Vieux 01/12/2006, 23h34   #2
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Merge all Lines into one?

2006-12-1, 15:30(-08), ryandle@gmail.com:
> Hello all.
>
> Im currently trying to take a file with a series of numbers on each
> line and merge them into one line. I also would like to insert a "+"
> between each one so that i can run binary calc on the file and add them
> all together. here is an example of what im trying to do.
>
>
> #file 1
> 45.34
> -234.33
> 96
> 54
> -4.33
>
> # i want to turn a file like that into a file with one line:
>
> 45.34+-234.33+96+54+-4.33

[...]

paste -sd+ 'file 1' > 'file 2'

paste -sd+ 'file 1' | bc

--
Stéphane
  Réponse avec citation
Vieux 01/12/2006, 23h40   #3
ryandle@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Merge all Lines into one?

I knew it was probably something simple, much thanks!

  Réponse avec citation
Vieux 01/12/2006, 23h46   #4
Ed Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Merge all Lines into one?

ryandle@gmail.com wrote:

> Hello all.
>
> Im currently trying to take a file with a series of numbers on each
> line and merge them into one line. I also would like to insert a "+"
> between each one so that i can run binary calc on the file and add them
> all together. here is an example of what im trying to do.
>
>
> #file 1
> 45.34
> -234.33
> 96
> 54
> -4.33
>
> # i want to turn a file like that into a file with one line:
>
> 45.34+-234.33+96+54+-4.33
>
> Is this possile? I am scripting in CSH. This is part of a project, so
> i have to use the CSH shell. Any and all ideas would be very ful!!
> If this is not possible, is there another way to add every number in
> that file? The file only consists of numbers, one per line. Thanks in
> advance!!
>


$ cat file1
45.34
-234.33
96
54
-4.33
$ awk -v RS= -v OFS=+ '$1=$1' file1
45.34+-234.33+96+54+-4.33

Ed.
  Réponse avec citation
Vieux 02/12/2006, 07h20   #5
John W. Krahn
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Merge all Lines into one?

ryandle@gmail.com wrote:
>
> Im currently trying to take a file with a series of numbers on each
> line and merge them into one line. I also would like to insert a "+"
> between each one so that i can run binary calc on the file and add them
> all together. here is an example of what im trying to do.
>
>
> #file 1
> 45.34
> -234.33
> 96
> 54
> -4.33
>
> # i want to turn a file like that into a file with one line:
>
> 45.34+-234.33+96+54+-4.33
>
> Is this possile? I am scripting in CSH. This is part of a project, so
> i have to use the CSH shell. Any and all ideas would be very ful!!
> If this is not possible, is there another way to add every number in
> that file?


$ echo "#file 1
45.34
-234.33
96
54
-4.33" | perl -ple'$\+=$_}{'
-43.32



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
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 16h58.


É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,12287 seconds with 13 queries