Monday, January 29, 2018

We discussed techniques for request chaining here:  https://www.blogger.com/blogger.g?blogID=1985795500472842279#editor/target=post;postID=859017183586117344;onPublishedMenu=allposts;onClosedMenu=allposts;postNum=0;src=link
The best way to establish chaining is with a common attribute specific only to the chaining. 
one such attribute is the customer id. For example, this untested but illustration only example for searching indicates the chaining is automatically established as part of selection:

#! /usr/bin/bash
#
if [ $# -ne 1 ]
then
 echo "Usage: chainer $0 customerId"
 exit $E_BADARGS
fi
listfiles=$(ls -d -1 $PWD/manaus*.*)
unset files
while IFS= read -r line
do
    files+=("$line")
done < <(echo "$listfiles")
echo $files
for file in ${files[@]}
do
  echo "file="; echo $file;
  search="zgrep -n \"^customerID=$1\" $file | cut -d\":\" -f1"
  echo $search; echo
  command_test=$(whatis "$search" | grep 'nothing appropriate');
  echo "search=";echo $search;
  unset linesno
  linesno=()
  if [[ -z "$command_test" ]]
  then
    echo "zgrep available"
    while IFS= read -r line
    do
        echo $line; echo
        linesno+=("$line")
    done < <(echo "$search")
  echo "linesno="; echo $linesno;
  for lineno in $linenos
  do
  if [! -z "$lineno" ]
  then
     echo "improper line no: $lineno"; echo
     continue;
  fi
  $text=`zcat $file | head -n $(($lineno-1+2)) | tail -n 3`
  echo $text; echo
  done
  else
  echo "no suitable command found"
  fi
done

: <<'output'
/home/ravi/manaus.tar.gz
file=
/home/ravi/manaus.tar.gz
zgrep -n "^customerID=food" /home/ravi/manaus.tar.gz | cut -d":" -f1
zgrep -n "^customerID=food" /home/ravi/manaus.tar.gz | cut -d":" -f1: nothing appropriate.
search=
zgrep -n "^customerID=food" /home/ravi/manaus.tar.gz | cut -d":" -f1
zgrep available
zgrep -n "^customerID=food" /home/ravi/manaus.tar.gz | cut -d":" -f1
linesno=
zgrep -n "^customerID=food" /home/ravi/manaus.tar.gz | cut -d":" -f1
output

No comments:

Post a Comment