Link to home
Start Free TrialLog in
Avatar of doc_jay
doc_jay

asked on

linux script help with dates

I have a script that I have to input a date into manually in the format of '20120915'.  I only need to work with the dates from '20120815' to 20121001'.  Could someone help me put some code together that could automatically insert these dates into a variable one by one into my script?  
Maybe a for loop would work in this case?

Here is the script I am working with:

#!/bin/bash
UTIL=/cygdrive/c/apps/dcm4che-2.0.25-bin/bin
INPUT=/cygdrive/c/projects/fill/comb
BASEDIR=/cygdrive/c/projects/fill
$UTIL/dcmqr RADARCH4@10.10.51.32:104 -rStudyInstanceUID -qStudyDate=20120915 | grep "(0020,000D) UI #[0-9]*" | sed s/'(0020,000D) UI #[0-9]* \['// | sed s/'\] Study Instance UID'// | sed s/'] Study Instance'// | sed s/'UI'// | sed s/'U'// > $BASEDIR/A4_SUID
$UTIL/dcmqr RADARCH2@10.10.50.51:104 -rStudyInstanceUID -qStudyDate=20120915 | grep "(0020,000D) UI #[0-9]*" | sed s/'(0020,000D) UI #[0-9]* \['// | sed s/'\] Study Instance UID'// | sed s/'] Study Instance'// | sed s/'UI'// | sed s/'U'// > $BASEDIR/A2_SUID
comm -2 -3 <(sort $BASEDIR/A4_SUID) <(sort $BASEDIR/A2_SUID) > $BASEDIR/comb
count=0
exec 3<&0 #Save stdin to file descriptor 3.
exec 0<$INPUT # Redirect standar input.
while read line
do
input1=$(echo $line | awk '{ print $1 }')
echo "Sending :" ${input1}
$UTIL/dcmqr RADARCH4@10.10.51.32:104 -q0020000D=${input1} -cmove RADARCH2
count=$( expr $count + 1 ) 
done
exec 0<$3 #restore old stdin.
echo "Counter:" $count # Show deleted items

Open in new window


The areas where the dates get inserted are
-qStudyDate=20120915

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of doc_jay
doc_jay

ASKER

-woolmilkporc

  -- awesome - thanks for great help on this.  If I insert the above code into my script as below, would it just run until it hit the 'end date'?

#!/bin/bash
UTIL=/cygdrive/c/apps/dcm4che-2.0.25-bin/bin
INPUT=/cygdrive/c/projects/fill/comb
BASEDIR=/cygdrive/c/projects/fill
start="20120815"
end="20121001"
DATES=""
for i in $(seq 0 9999)
 do
  new=$(date -d "$start + $i days" "+%Y%m%d")
  if [[ $new -le $end ]]; then DATES=$DATES $new"; else break; fi
done
for D in $DATES
 do
  $UTIL/dcmqr RADARCH4@10.10.51.32:104 -rStudyInstanceUID -qStudyDate=$D | grep "(0020,000D) UI #[0-9]*" | sed s/'(0020,000D) UI #[0-9]* \['// | sed s/'\] Study Instance UID'// | sed s/'] Study Instance'// | sed s/'UI'// | sed s/'U'// > $BASEDIR/A4_SUID
  $UTIL/dcmqr RADARCH2@10.10.50.51:104 -rStudyInstanceUID -qStudyDate=$D | grep "(0020,000D) UI #[0-9]*" | sed s/'(0020,000D) UI #[0-9]* \['// | sed s/'\] Study Instance UID'// | sed s/'] Study Instance'// | sed s/'UI'// | sed s/'U'// > $BASEDIR/A2_SUID
 done
comm -2 -3 <(sort $BASEDIR/A4_SUID) <(sort $BASEDIR/A2_SUID) > $BASEDIR/comb
count=0
exec 3<&0 #Save stdin to file descriptor 3.
exec 0<$INPUT # Redirect standar input.
while read line
 do
  input1=$(echo $line | awk '{ print $1 }')
  echo "Sending :" ${input1}
  $UTIL/dcmqr RADARCH4@10.10.51.32:104 -q0020000D=${input1} -cmove RADARCH2
  count=$( expr $count + 1 ) 
 done
exec 0<$3 #restore old stdin.
echo "Counter:" $count # Show deleted items

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of doc_jay

ASKER

--woolmilkporc

  Yes, that is the way I was wanting the script to behave, that is for the script to process only one day at a time.  I just wasn't sure where to place the "done", but I have tested it out and it works as I had hoped.

thanks for all of the help- you're very knowledgeable.