samedi 28 février 2015

Sed regex printing into a file.txt


I'm connected to a MQTT stream, and I filter out the data by entering :



mosquitto_sub -d -t +/# 2>&1 |
sed -n "/PUBLISH/{s|.*\('.*',\).*|\1$(date),|;N;s/\n//;p}"


into the Ubuntu terminal. This prints the only things that I am interested from the MQTT stream.


Now that I can do this I would like to dump this information into a qwerty.TXT file. I've tried



mosquitto_sub -d -t +/# 2>&1 |
sed -n "/PUBLISH/{s|.*\('.*',\).*|\1$(date),|;N;s/\n//;w qwerty.txt}"


and got the following error:



sed: -e expression #1, char 0: unmatched '{'


I've looked into sed regex, and the examples are that w file.type writes into the file file.type where type can be .txt for example.


I've also tried



mosquitto_sub -d -t +/# 2>&1 |
sed -n "/PUBLISH/{s|.*\('.*',\).*|\1$(date),|;N;s/\n//;p >> qwerty.txt}"


and



mosquitto_sub -d -t +/# 2>&1 |
sed -n "/PUBLISH/{s|.*\('.*',\).*|\1$(date),|;N;s/\n//;1a qwerty.txt}"


How can I print my filtered MQTT stream into a file named qwerty.txt?



Aucun commentaire:

Enregistrer un commentaire