So i have a file "scenes.txt", containing a 2-column set of numbers, about 500 lines in total:
0 01
6 22
5 03
4 97
7 05
3 98
2 99
9 00 etc...
First column range is 0-9, second column range is 0-99. The 2 fields are tab-separated. On each invocation of the shell script, I want the script to output the set of the 2 numbers from the next line in the list to 2 variables.
So if I run the script for the first time, var1 should be 0 and var2 should be 01, on the next run of the script var1 should be 6 and var2 should be 22, and so on...
These values are going to the sendmidi command, https://github.com/gbevin/SendMIDI, to control a piece of hardware via MIDI.
You could call it a clumsy MIDI command line sequencer.
what I tried so far: I created a bash script "test1":
#!/bin/bash
read LINECNT < pointer
echo "next line to be processed: $LINECNT"
VAR1=$(sed "${LINECNT}q;d" scenes.txt)
echo "Line and Variables: $LINECNT: $VAR1"
# here the actual magic happens:
/usr/local/bin/sendmidi dev "USB2.0-MIDI Anschluss 2" cc 32 $VAR1 PC $VAR2
((LINECNT++))
echo $LINECNT > pointer
and another file named "pointer", which just holds the pointer position for the value to output upon next invocation.
File pointer:
1
This results in:
[dirk@dirks-MacBook-Pro] ~
❯ ./test2
next line to be processed: 1
Line and Variables: 1: 0 01
[dirk@dirks-MacBook-Pro] ~
❯ ./test2
next line to be processed: 2
Line and Variables: 2: 6 22
[dirk@dirks-MacBook-Pro] ~
❯ ./test2
next line to be processed: 3
Line and Variables: 3: 5 03
[dirk@dirks-MacBook-Pro] ~
❯ ./test2
next line to be processed: 4
Line and Variables: 4: 4 97
[dirk@dirks-MacBook-Pro] ~
❯ ./test2
next line to be processed: 5
Line and Variables: 5: 7 05
My Problem:
There are two Values in each line of "scenes.txt", but the
VAR=$(sed "${LINECNT}q;d" scenes.txt)
line only gives the whole line with both values.
I tried several "cut" modifications, like this
VAR1=cut -f1 - $(sed "${LINECNT}q;d" scenes.txt)
VAR2=$(cut -f2 $(sed "${LINECNT}q;d" scenes.txt))
but with no luck... How do I push the two values from that line into VAR1 and VAR2?