BASH Script help re-write

My original script:

awk -v S=$START -v E=$END 'NR>=S&&NR<=E {print $1}' $INPUT  | while read input1  #starting at a certain row
 echo "Row $count" | tee -a rowcount25k.txt
 echo "Moving :" ${input1}
 $UTIL/findscu -c STORESCP@ -m 00080050=${input1} -r0020000D --out-dir /opt/notes/cs1fill/2017/0020000D --out-file suid.txt
 $UTIL/movescu -c STORESCP@ -m 0020000D=${suid1} --dest cs1FIR
   if (( cnt == 50 )); then
    echo "Sleeping for 5 Seconds on $(date), I have moved $count exams"
    sleep 5
exec 0<$3 #Restore old stdin.
echo "Counter:" $((count-START)) # Show moved items

The first command will read from input1 (a list of numbers with one column) and will write to a file named 'suid.txt'.

The 2nd command will read from the file 'suid.txt' to perform the last task.

My problem is that the first command that runs 'findscu' will overwrite the 'suid.txt' instead of adding to it, so I need the 2nd command to finish its task and then go back to the 1st command until it is finished reading from 'input1'.

How can I re-write this to make it do what I expect?

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David FavorLinux/LXD/WordPress/Hosting SavantCommented:
This appears to be a side effect of your findscu program.

You might be able to fix this by...

# Changing this line...
 $UTIL/findscu -c STORESCP@ -m 00080050=${input1} -r0020000D --out-dir /opt/notes/cs1fill/2017/0020000D --out-file suid.txt

# To something like this...
 $UTIL/findscu -c STORESCP@ -m 00080050=${input1} -r0020000D --out-dir /opt/notes/cs1fill/2017/0020000D --out-file - >> suid.txt

Open in new window

Whether or not this will work depends on your findscu code.

In most cases, changing a filename to "-" will emit output on STDOUT, rather than into a file.

The >> suid.txt says to append to the file, rather than overwrite it's contents.
doc_jayAuthor Commented:

I tried that out and it didn't append, I guess thats just how the 'findscu' is written maybe.  Is there a way that the script can be written to force the 2nd command to run, which needs to read the 'suid.txt' before its overwritten by reading 'input'?

David FavorLinux/LXD/WordPress/Hosting SavantCommented:
Just run the command without a file operation, like this...

 $UTIL/findscu -c STORESCP@ -m 00080050=${input1} -r0020000D --out-dir /opt/notes/cs1fill/2017/0020000D --out-file -

Open in new window

And post what output occurs.

You should see all the output scroll across your terminal.
Acronis Data Cloud 7.8 Enhances Cyber Protection

A closer look at five essential enhancements that benefit end-users and help MSPs take their cloud data protection business further.

doc_jayAuthor Commented:
Okay - I gave that a shot.  Seemed to work as it was written.

The 'findscu' command ran just fine and did what what it was supposed to do, it wrote what it found to the out-put directory into a file named '-1'.
David FavorLinux/LXD/WordPress/Hosting SavantCommented:
If findscu outputs to STDOUT, then you should be able to use >> suid.txt at the end of your command to append your suid.txt file.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
David FavorLinux/LXD/WordPress/Hosting SavantCommented:
Marked one of my answers as best.

Poster seems to have had question answered.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.