|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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!! |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
I knew it was probably something simple, much thanks!
|
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
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 |
|
![]() |
| Outils de la discussion | |
|
|