[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: ReadLines and Substraction
From: |
Andres Perera |
Subject: |
Re: ReadLines and Substraction |
Date: |
Mon, 14 Mar 2011 12:44:19 -0430 |
On Mon, Mar 14, 2011 at 6:38 AM, pk <pk@pk.invalid> wrote:
> yetcom wrote:
>
>> Hello Everyone,
>>
>> I have an issue regarding the bash. I have 2 different files and each
>> of them involves some float point numbers for each lines. I want to
>> subtract each line then put all the results into a file. The first
>> line float number will be subtract with the first line of other file
>> and the second with the other second... and etc...
>>
>> When I read both files with:
>>
>> cat ./Temp1.log | while read line; do
>>
>> cat ./Temp2.log | while read line; do
>>
>> #It reads the first line of temp1, I also need to read the
>> first line of temp2. However, Temp2 will be read until the end of file
>> so that I cannot read one by one for each lines of different files.
>>
>> done
>>
>> done
>>
>>
>> If you can help me with this, will be very happy for that. Thanks in
>> advance.
#!/usr/bin/env bash
set -e
if [[ $(type -t 'mapfile') != 'builtin' ]]
then
function mapfile
{
while getopts C:c: f
do
case $f in
C) cmd=$OPTARG;;
c) rep=$OPTARG;;
esac
done
shift $((--OPTIND))
i=0
while read -r n
do
!((i % rep)) && eval "$cmd"
: $(($1[i++] = n))
done
}
fi
(((files = $#) >= 2))
while (($#))
do
[[ $1 ]]
mapfile -C'let ++lno #' -c1 par_$# < <(egrep '^[0-9]+$' "$1")
shift
done
((lno && ((lno / files) == ${#par_1[@]})))
for i in ${!par_1[@]}; do
for ((j=1; j <= files-1; j++)); do
: $((par_$files[i] -= par_$j[i]))
done
printf '%d\n' $((par_$files[i]))
done
exit
>
> try
>
> paste -d '-' file1 file2 | bc > results
>
>
>