Как выполнить следующую задачу в bash?
Мне нужно написать скрипт, который запускает скрипт python в каждой строке текстового файла в качестве отдельного входа, а затем сохраняет результат в json-файле названный в честь строки, с которой он считывает файл.
Итак, текстовый файл 10tweets.txt выглядит следующим образом:
cat 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 "$@" в сценарии bash и связывать его с каждой строкой из файла. Как работает сценарий, как показано ниже
$ 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
В котором, например, вход в сценарий можно считать первой строкой файла.
В принципе, выполняется следующее bash скрипт анализирует только последнюю строку файла и сохраняет его в 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
Вот фрагмент того, что происходит, когда я запускал предложение в bash IRC-канале: https://pastebin.com / raw / VQpPFJYs и https://pastebin.com/raw/GQefrTX0
Благодаря сообществу IRC bash
#!/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
Вы можете 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 "$@" было бы полезно. [ ! d1]
Благодаря сообществу IRC bash
#!/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
Вы можете 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 "$@" было бы полезно. [ ! d1]