vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| I want to read a certain value from a usb device printout, like this: asterisk:/proc# k8055 -m:1 Velleman Device Found @ Address 018 Vendor 0x010cf Product ID 0x05500 get driver name: could not get bound driver: No data available Found interface 0 Took over the device 232;0;119;132;2;1 The value I'm interested in is the last line 232;0;119;132;2;1 and then the second value (in this case 0) I've been trying with the 'cut' command. But I don't know how to pick out only the last line. May be I need another approach. (?) rgds Henk |
| |||
| Henk Oegema wrote: > I want to read a certain value from a usb device printout, like this: > > asterisk:/proc# k8055 -m:1 > Velleman Device Found @ Address 018 Vendor 0x010cf Product ID 0x05500 > get driver name: could not get bound driver: No data available > Found interface 0 > Took over the device > 232;0;119;132;2;1 > > > The value I'm interested in is the last line > 232;0;119;132;2;1 > and then the second value (in this case 0) > > I've been trying with the 'cut' command. But I don't know how to pick out > only the last line. > May be I need another approach. (?) > > rgds > Henk > > > > Not sure how clean this would be for your purpose, but for the 'last' of something I sometimes do something like this: for line in `cat /etc/passwd`; do : done; echo $line; Will give you the last line of /etc/passwd.... The easier way would be a `tail -1` - not as expensive as the loop....except that in the loop, you could also grab your second line. JR. -- Bill will have to take Linux from my cold, dead flippers. -Tux. |
| |||
| Johnny Rebel wrote: > Not sure how clean this would be for your purpose, but for the 'last' of > something I sometimes do something like this: > > for line in `cat /etc/passwd`; do > : > done; > echo $line; > > > Will give you the last line of /etc/passwd.... The easier way > would be a `tail -1` - not as expensive as the loop....except that in > the loop, you could also grab your second line. > I've been trying to 'pipe' to output with different options of tail, but it always prints all lines. asterisk:~# k8055 -m:1 | tail -n-1 Velleman Device Found @ Address 018 Vendor 0x010cf Product ID 0x05500 get driver name: could not get bound driver: No data available Found interface 0 Took over the device 306;0;118;132;2;1 asterisk:~# |
| |||
| Henk Oegema wrote: The problem is solved. When I do a asterisk:/home/henkoegema# k8055 -m:1 is shows: Velleman Device Found @ Address 018 Vendor 0x010cf Product ID 0x05500 get driver name: could not get bound driver: No data available Found interface 0 Took over the device 225;0;119;132;2;1 When I do asterisk:/home/henkoegema# k8055 -m:1 > test it only shows 225;0;119;132;2;1 in the file. |
| |||
| Henk Oegema wrote: > Henk Oegema wrote: > > The problem is solved. > > When I do a > asterisk:/home/henkoegema# k8055 -m:1 > is shows: > Velleman Device Found @ Address 018 Vendor 0x010cf Product ID 0x05500 > get driver name: could not get bound driver: No data available > Found interface 0 > Took over the device > 225;0;119;132;2;1 > > When I do > asterisk:/home/henkoegema# k8055 -m:1 > test > > it only shows > 225;0;119;132;2;1 > in the file. The only disadvantage is that I have to create a file first. Can't the value 0 (in the line 225;0;119;132;2;1) be assigned directly to a bash variable ? (without reading it from a file) |
| |||
| On Sun, 24 Feb 2008 21:55:00 +0100, Henk Oegema wrote: > Henk Oegema wrote: > > The problem is solved. > > When I do a > asterisk:/home/henkoegema# k8055 -m:1 is shows: > Velleman Device Found @ Address 018 Vendor 0x010cf Product ID 0x05500 > get driver name: could not get bound driver: No data available Found > interface 0 > Took over the device > 225;0;119;132;2;1 > > When I do > asterisk:/home/henkoegema# k8055 -m:1 > test > > it only shows > 225;0;119;132;2;1 > in the file. Probably the first few lines go to stderr. I'd try: k8055 -m:1 2>/dev/null | tail -1 | cut -d';' -f2 |
| |||
| Björn Steinbrink wrote: > Probably the first few lines go to stderr. I'd try: > > k8055 -m:1 2>/dev/null | tail -1 | cut -d';' -f2 Yes Björn, this gives me the wanted output. See: asterisk:/home/henkoegema# k8055 -m:1 2>/dev/null | tail -1 | cut -d';' -f2 0 <-------- asterisk:/home/henkoegema# One of my mistakes in the 'cut' command was d: i.s.o. d';' Only one step left now: How can I assign the output to a bash variable ? |
| |||
| Henk Oegema wrote: > Björn Steinbrink wrote: > >> Probably the first few lines go to stderr. I'd try: >> >> k8055 -m:1 2>/dev/null | tail -1 | cut -d';' -f2 > > Yes Björn, this gives me the wanted output. > > See: > asterisk:/home/henkoegema# k8055 -m:1 2>/dev/null | tail -1 | cut -d';' -f2 > 0 <-------- > asterisk:/home/henkoegema# > > One of my mistakes in the 'cut' command was d: i.s.o. d';' > > Only one step left now: > How can I assign the output to a bash variable ? > > var=`<command>` Put var= in front of it, and use back-ticks around the whole thing. This will assign the value of it to the var. JR. -- Bill will have to take Linux from my cold, dead flippers. -Tux. |
| ||||
| Henk Oegema wrote: > Johnny Rebel wrote: > >> var=`<command>` >> >> Put var= in front of it, and use back-ticks around the whole thing. >> This will assign the value of it to the var. >> > Thanks Johnny. No problems, glad to help! JR. -- Bill will have to take Linux from my cold, dead flippers. -Tux. |