谢谢你的帮助!你知道吗
我想要一个shell脚本从txt文件中读取最后一个值。我从python脚本中得到了这个(另一个脚本),但在shell脚本中不起作用。我发现一些帮助脚本部分在这里和那里(在stackoverflow)但我不能得到这个工作。你知道吗
如何从txt文件中读取最后一个值(回火.txt)在shell脚本中?你知道吗
txt文件:
1个
二
三
4个
五
六
七
Shell脚本:
#!/bin/bash
# Domoticz server
SERVER="192.168.0.30:8080"
# IDX DHT
# The number of the IDX in the list of peripherals
DHTIDX="1"
# temp file with the counting
TMPFILE="/var/tmp/temper.txt"
# old piece of the script. not used
#sudo nice -20 Adafruit_DHT 2302 $DHTPIN > $TMPFILE
# 5 seconds for testing
sleep 5
# piece of the script where I want to read the last value form the TEMPFILE!
PULS=$(cat $TMPFILE|grep .... last value... |awk '.... last value ....' |sed -r 's/^.*=//' | sed -r 's/\*//')
echo "PULS: $PULS"
# send data
curl -s -i -H "Accept: application/json" "http://$SERVER/json.htm?type=command¶m=udevice&idx=$DHTIDX&nvalue=0&svalue=$PULS"
PULS=""
#rm $TMPFILE
exit 0
fi
echo "CPT: $cpt"
cpt=$(($cpt+1))
done
exit 1
tail -1 <filename>
将输出文件中的最后一行。如果你所说的last value
是指last line
,那么这就行了。你知道吗相关问题 更多 >
编程相关推荐