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?
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.
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'?

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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.
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:
Marked one of my answers as best.

Poster seems to have had question answered.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.