0

I want to run a shell script to gather Twitter data with t. I don't want to overwrite existing files so how can I define s.th. like

If there is a file called twitter.csv in the folder then create a new file called twitter2.csv ... or open twitter.csv and add new data

cd data

t timeline @twitter --csv --number 3000 > twitter.csv

cd ..

1 Answer 1

1
file=twitter.csv
[[ -e $file ]] && file=twitter2.csv

t timeline @twitter --csv --number 3000 > "$file"

If you want to generalize this so it looks for the first unused twitter<N>.csv, you could do:

file=twitter.csv; i=1
while [[ -e $file ]]; do file=twitter$((++i)).csv; done

t timeline @twitter --csv --number 3000 > "$file"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.