Bash String Handling
Hi All, yet again I cannot get string handling in bash into my head, I don't do enough of itso here goes:
Quote:
If more than 30 then I'll report it via echo |
You can split it via a read command.
Code:
IFS=":" read a b c d e <<< "720x480 | crop=656:480:22:32 : MyMovie.mp4" Code:
[[ "720x480 | crop=656:480:22:32 : MyMovie.mp4" =~ ^[^:]*:[^:]*:([^:]*):([^:\ ]*) ]] |
regex. Allows you to also easily check you are testing the correct record.
Lot easier with bash these days than it used to be. |
or you can use arrays, if you wish:
Code:
var="720x480 | crop=656:480:22:32 : MyMovie.mp4" |
Thank you everybody, that's brilliant - I was thinking awk was a possible solution, actually it probably is.
I could easily do this in SQL but that's becasue I've been using it for 30+ years! |
Quote:
But could you explain the mask and why its 1 and 2 in the BASH_REMATCH array |
man bash
Quote:
Also ${BASH_REMATCH[0]} is the total matching portion, like grep -o would report it. |
Quote:
|
Just for fun
Code:
v1=echo ' 720x480 | crop=656:480:22:32 : MyMovie.mp4 '|cut -d':' -f3 |
All times are GMT -5. The time now is 08:29 PM. |