I'm trying to access the data to the right of the colon but I am unable to. When I try to display it I get a blank response. Can anyone tell how to get around the braces so I can access the date and display it or use it for a condition statement? I appreciate any help. Thanks in advance! command response:
{
“DATE1” : 000,
“DATE2” : 111,
“DATE3” : 222
}my code:
i=1
while [[ $i -ne 4 ]] ; do
T=data|cut -d':' -f2
echo $i is $T
i=$(($i+1))
done
I don't think cut is thie best tool. How about awk. I am assuming you do not want the commas. Let me know if you have any questions: #!/bin/ksh # use awk if you are NOT using Solaris nawk ' BEGIN { FS=":" } { if(NF > 1) { gsub(",", "") # delete comma gsub(" ","") # gett rid of leading space print $NF # print last field } } ' data.txt Here is another way parsing with the shell: while IFS=":" read first therest do if [ ! -z $therest ] then # print only if defined therest=$(echo $therest| tr -d ',') echo $therest fi done < data.txt
Yes (14) | ![]() | |
No (14) | ![]() | |
I don't know (15) | ![]() |