Как я могу выполнить следующую задачу в ударе?
Я должен записать сценарий, который запускает скрипт Python на каждой строке текстового файла как вход отдельно и затем сохраняет результат в json файле, названном в честь строки, из которой это читает файл.
Так текстовый файл 10tweets.txt похож ниже:
кошка 10tweets.txt
Trump on the other hand goes all in on water boarding AND some. #GOPDebate
RT @wpjenna Donald Trump promises that he will not touch the 2nd amendment -- "unless we're going to make it stronger."
Trump 23%, Rubio 19%, Kasich & Bush 14%, Christie 10%, Cruz 9% #NHPrimary
@realDonaldTrump Thank you for saying you won't use vulger language anymore. Talk about Sanders & Clinton. Take Cruz as VP. Mexican votes!!!
RT @SurfPHX Mr. Trump @realDonaldTrump tweeted 25 minutes ago. You all do realize, that our future President hardly sleeps. He's a Fighter and a Worker!
go, Bernie #DemDebate
Sanders calls out Clinton on taking Foreign Policy advice from Warmonger Henry Kissinger https://t.co/xT5J4uh4m4 via @YouTube
Cruz, Rubio, and the Moral Bankruptcy of Progressive Identity Politics https://t.co/kSQstJXtKO via @NRO
RT @scarylawyerguy "Who does Bernie Sanders listen to on foreign policy." - A question Hillary had to raise b/c the media will not. #DemDebate
Why Did U of California Fire Tenured Riverside Professor? / Ted Cruz and Higher Ed -- ... - https://t.co/zFxa4Q70wh
и я хочу вывод быть похожим 1.json, 2.json, 3.json, 4.json, 5.json в выходной папке.
Не уверенный, как использовать exec entity_sentiment.py "$@"
в сценарии удара и ссылке это к каждой строке из файла. Путем сценарий, работал, похож ниже
$ python entity_sentiment.py sentiment-entities-text "Thank you for saying you won't use vulger language anymore"
Mentions:
Name: "vulger language"
Begin Offset : 35
Content : vulger language
Magnitude : 0.699999988079071
Sentiment : -0.699999988079071
Type : 2
Salience: 1.0
Sentiment: magnitude: 0.699999988079071
score: -0.699999988079071
В котором, например, вход к сценарию мог быть принят первая строка файла.
В основном запущение следующего скрипта удара только анализирует последнюю строку файла и сохраняет его в 1.json
#!/bin/bash
n=1
while read -u 3 -r line; do
python entity_sentiment.py sentiment-entities-text "$line" > "$((n++)).json"
done 3< 10tweets.txt
Вот отрывок того, что происходит, когда я выполнил предложение в ударе канал IRC: https://pastebin.com/raw/VQpPFJYs и https://pastebin.com/raw/GQefrTX0
Вы можете read
входной файл линию за линией и применяет команду к каждой строке с помощью чего-то как
#!/bin/bash
n=1
while read -r line; do
python entity_sentiment.py sentiment-entities-text "$line" > "$((n++)).json"
done < input.txt
Я не вижу как exec entity_sentiment.py "$@"
было бы полезно.
Благодаря IRC колотят сообщество
#!/bin/bash
n=1
while read -u 3 -r line; do
echo $n "${line::30}"
python entity_sentiment.py sentiment-entities-text "$line" > "$((n++)).json"
((n++))
done 3< 10tweets.txt