bash - Is there way of distinguishing between characters and numbers? -
i've got bash script, interprets incoming datum. hoping if there way of bash realizing whether it's combination of letters example hi
, bye bye
or numbers 123451
.
what snippet of code like??
awk_variables=`echo "$line" | awk -f, '{print $1, $4, $5, $7, $10 }'` awk_variables_value_array=($awk_variables) #turns contents of 'awk_variables' array 'awk_variables_value_array'
^ part of code reading ($)line
csv file. it's here datum 'hello' or numbers if thats case don't want read it. $4
have letters when gets read.
q: script if able distinguish datum letters , numbers?
ideally: alternative approach if bit of code count how many parameters there in given ($)line
. if parameters not equal x amount, not read it, , skip next line. q: script like?
to split line (here, $line
) array (here, ${array[@]}
) using ,
delimiter:
ifs=, read -r -a array <<<"$line"
to see how many values put array:
${#array[@]}
to see if specific element consists of numbers:
! [[ ${array[4]} =~ [^0-9] ]]
(the !
go inside [[...]]
. adjust character class if want include negative numbers, decimal points, etc.)
Comments
Post a Comment