I have thought about this for quite some time and know what I want to do but am having some trouble at it. I have a text file filled with numbers like this, there are more in the file obviously. Each number is separated by a space.
1 3 2 4 5
1 -1 1 0 -1 5
The idea is to use these numbers to calculate some kind of a profit. The first line is price per item and the second line indicates an action. 1 means you bought it, -1 means you sold it, 0 means no action. So, to demonstrate things, you buy an item at $1, the running total is -1, you sell (add 3), subtract 2, ignore the no transaction, then add 5, leaving you with 5. Anyway I am trying to read 2 lines in at a time in TSCH (don’t respond telling me that it’s harmful, I have to use it in this situation) and check to see whether the ending profit is correct. I am thinking I can read in 2 lines at once, store them in different variables, and then compute a running total for the lines by using indexes in each variable. Saying, comparing line1[0] and line2[0] and so on. If line2[i] is negative that means add and vice versa. If anyone offer a solution or point me in the right direction I would greatly appreciate it! I have one line being read in but do not know how to get the second line.
set lines=`cat $PWD/testcase.txt`
set i=1
while ($i <= $#lines)
echo $lines[$i]
@ i = $i + 1
end
From: http://www.unix.com/shell-programming-scripting/221059-reading-two-lines-once-text-file.html