The UNIX and Linux Forums  


Go Back   UNIX och Linux Forum > Upp Forum > Shell-programmering och Skript
.
google unix.com



Shell-programmering och Skript Post frågor om ksh, CSH, SH, bash, PERL, PHP, sed, awk och andra skalskript och skal skriptspråk här.

Mer UNIX och Linux Forum Ämnen Du kan hitta Helpful
Tråd Thread Starter Forum Svar Senaste Inlägg
sammanfattning hjälp uwork72 Shell-programmering och Skript 4 09-07-2008 09:56
Hur sammanfattningen en kommandots processoranvändning? jiarong.lu HP-UX 1 02-22-2008 11:03
grep kör totalt / slutliga totala över flera filer Mrad UNIX for Dummies Frågor & Svar 5 05-08-2007 02:03
System Sammanfattning Verktyg Vaders UNIX for Dummies Frågor & Svar 2 07-03-2002 03:28

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Sök i denna tråd Rate Thread Visningslägen
  #1 (permalänk)  
Old 04-22-2009
xiaojesus xiaojesus is offline
Registered User
  
 

Join Date: april 2009
Inlägg: 20
hur du lägger upp totalt i en sammanfattande rapport?

Hej alla Jag har ett manus, men jag skränande lägga upp den sammanfattande rapporten .. hålla med synax fel. åtanke att hjälpa mig att ta en titt och berätta vad som gick fel ..

Jag vet är lite lång, men jag hoppas någon kan Hep mig med det. tack

felmeddelandet kommer upp när jag försöker köra den sammanfattande rapporten ..

Jag antar att 1 av problemet är det system date.thing.

problemet handlar om i butikerna.

Jag försöker att lägga upp alla dagliga försäljningen och sedan har en totalsumman av all försäljning av alla dagar.
nedan är koden.





Kod:
# Global variables
POS=~/.Point_Of_Sales
POS=POS.txt
export POS

confirm()
{
  echo -en "$@"
  read ans
  ans=`echo $ans | tr '[a-z]' '[A-Z]'`
  if [ "$ans" == "Y" ]; then
    return 0
  else
    return 1
  fi
}

num_lines()
{
  grep -i "$@" $POS|wc -l| awk '{ print $1 }'
}

find_lines()
{
  # Find lines matching $1
  res=-1
  if [ ! -z "$1" ]; then
    grep -i "$@" $POS
    res=$?
  fi
  return $res
}

list_items()
{
  # List items matching given search criteria
  if [ "$#" -eq "0" ]; then
    echo -en "Search for: (return to list all) "
    read search
    if [ -z "$search" ]; then
      search="."
    fi
    echo
  else
    search="$@"
  fi
  find_lines "${search}" | while read i
  do
    echo "$i" | tr ':' '\t'
  done
  echo -en "Matches found: "
  num_lines "$search"
}

add_item()
{
  echo "Add Item: You will be prompted for 3 items:"
  echo "- Item Description, Unit Price, Quantity Purchased -"
  echo
  echo -en "Item Description:"
  read product
  echo -en "Unit Price:"
  read Unit_Price
  echo -en "Quantity:"
  read Quantity
  Date_Purchased=$(date +"%d %b %Y")  
  

  echo "${product}:${Unit_Price}:${Quantity}:${Date_Purchased}" >> $POS
}

locate_single_item()
{
  echo -en "Item to search for: "
  read search
  n=`num_lines "$search"`
  if [ -z "$n" ]; then
    n=0
  fi
  while [ "${n}" -ne "1" ]; do
    #list_items "$search"
    echo -en "${n} matches found. Please choose a "
    case "$n" in 
      "0") echo "less" ;;
      "*") echo "more" ;;
    esac
    echo "specific search term (q to return to menu): "
    read search
    if [ "$search" == "q" ]; then
      return 0
    fi
    n=`num_lines "$search"`
  done
  return `grep -in $search $POS |cut -d":" -f1`
}

remove_item()
{
  locate_single_item
  search=`head -$? $POS | tail -1|tr ' ' '.'`
  if [ -z "${search}" ]; then
    return
  fi
  list_items "$search"
  confirm "Remove?"
  if [ "$?" -eq "0" ]; then
    grep -v "$search" $POS > ${POS}.tmp ; mv ${POS}.tmp ${POS}
  else
    echo "NOT REMOVING"
  fi
}

edit_item()
{
  locate_single_item
  search=`head -$? $POS | tail -1|tr ' ' '.'`
  if [ -z "${search}" ]; then
    return
  fi
  list_items "$search"
  thisline=`grep -i "$search" $POS`
  oldProduct=`echo $thisline|cut -d":" -f1`
  oldUnitPrice=`echo $thisline|cut -d":" -f2`
  oldQuanity=`echo $thisline|cut -d":" -f3`
  echo "SEARCH : $search"
  grep -v "$search" $POS > ${POS}.tmp ; mv ${POS}.tmp ${POS}
  echo -en "Item Description: [ $oldProduct ] "
  read Product
  echo -en "Unit Price[ $oldUnitPrice ] "
  read Unit_Price
  echo -en "Quanity [ $oldQuanity ] "
  read Quanity
  Date_Purchased=$(date +"%d %b %Y")  
  echo "${Product}:${Unit_Price}:${Quanity}:${Date_Purchased}" >> $POS
}
summary_items()
{
  #echo "- - - POS Summary Report - - -"
  #echo "---------------------------"
  #echo "Date       Total POS"
  #echo "---------------------------"
  print_dtotal
  #echo "---------------------------"
  #print_gtotal
  #echo "---------------------------"
  #echo -en "Best Selling Product: "
  #print_bestsell
  #echo -en "Product with Highest POS: "
  #print_phighPOS
  #echo -en "Date with Highest POS: "
  print_dtotal | sort -f4| while read z
    do
        echo $z | cut -f4 -d' '
        return 0
    done
  echo
  echo -en "Press Enter to continue..."
  read
}
print_dtotal()
{
  count=0
  grep -i : $POS | cut -d: -f4 | sort -u | while read i
    do
        dtotal=0
    grep -i "$i" $POS | while read x
        do
            count=`expr $count + 1`
            temp1=`echo $x | cut -d: -f2 | cut -c2-`
            temp2=`echo $x | cut -d: -f3`
            temp3=`calcu_m $temp1 $temp2`
                        dtotal=`calcu_a $dtotal $temp3`
            n=`num_lines "$i"`
               if [ "${n}" -eq "${count}" ]; then
                echo  $i"        $"$dtotal
              fi
        done
    done 

}
print_gtotal()
{
  gtotal=0
  grep -i : $POS | while read x
    do
        temp1=`echo $x | cut -d: -f2 | cut -c2-`
        temp2=`echo $x | cut -d: -f3`
        temp3=`calcu_m $temp1 $temp2`
                gtotal=`calcu_a $gtotal $temp3`
        n=`num_lines "$i"`
           if [ "${n}" -eq "${count}" ]; then
            echo  "Grand Total      $"$gtotal
          fi
        count=`expr $count + 1`
    done 

}
print_bestsell()
{
   grep -i : $POS | sort -k4 -r -t: | while read bs
    do
           echo $bs | cut -d: -f1
        return 0
    done
}
print_phighPOS()
{
      count=0
        phigh="0.0"
    grep -i : $POS | while read x
        do
            count=`expr $count + 1`
            temp1=`echo $x | cut -d: -f2 | cut -c2-`
            temp2=`echo $x | cut -d: -f3`
            temp3=`calcu_m $temp1 $temp2`
            comparex $temp3 $phigh
               if [ "$?" -eq "0" ]; then
                phigh=$temp3
                phighx=`echo $x | cut -d: -f1`
              fi
            n=`num_lines ":"`
               if [ "${n}" -eq "${count}" ]; then
                echo  $phighx
              fi
        done
}
comparex()        # compare 2 decimal numbers $1 $2 eg 1.20 and 3.60
{
    x1=`echo $1 | cut -d. -f1`
    x2=`echo $1 | cut -d. -f2`
    y1=`echo $2 | cut -d. -f1`
    y2=`echo $2 | cut -d. -f2`
    if [ "${x1}" -gt "${y1}" ]; then
        return 0
    elif [ "${x1}" -eq "${y1}" ]; then
        if [ "${x2}" -gt "${y2}" ]; then
            return 0
        fi
    fi
    return 1
}
calcu_a()        # add 2 decimal numbers $1 $2
{
    x1=`echo $1 | cut -d. -f1`
    x2=`echo $1 | cut -d. -f2`
    y1=`echo $2 | cut -d. -f1`
    y2=`echo $2 | cut -d. -f2`
    x1=`expr $x1 + $y1`
    x2=`expr $x2 + $y2`
    x3=`expr $x2 \/ 100`
    x1=`expr $x1 + $x3`
    x2=`expr $x2 \% 100`
    echo $x1"."$x2
}
calcu_m()        # multiply 2 decimal numbers $1 $2
{
    x1=`echo $1 | cut -d. -f1`
    x2=`echo $1 | cut -d. -f2`
    y=`echo $2`
    x1=`expr $x1 \* $y`
    x2=`expr $x2 \* $y`
    x3=`expr $x2 \/ 100`
    x1=`expr $x1 + $x3`
    x2=`expr $x2 \% 100`
    echo $x1"."$x2
}

  #2 (permalänk)  
Old 04-22-2009
giannicello giannicello is offline
Registered User
  
 

Join Date: Sep 2001
Ort: Phoenix
Inlägg: 169
Vad händer när du flyttar funktion print_dtotal () ovan summary_items ()?
  #3 (permalänk)  
Old 04-22-2009
xiaojesus xiaojesus is offline
Registered User
  
 

Join Date: april 2009
Inlägg: 20
Hej alla, nedan Jag förmodar att knappa in och skriv in den dagliga försäljningen i systemet.

och jag förmodar att få det dagliga totala försäljningen och den totala försäljningen när jag ber om översikten över
Nedan finns en kod som jag måste skriva .. kan någon hjälpa?

funktionen doesnt verkar bea ble till reconise systemet dag och promt mig en syntaxerror ..




Kod:
#Enter and add in the Item detail, Item Price and Quantity Purchased into the system.
add_item()
{
  echo "Add Item: You will be prompted for 3 items:"
  echo "- Item Description, Unit Price, Quantity Purchased -"
  echo
  echo -en "Item Description:"
  read product
  echo -en "Unit Price:"
  read Unit_Price
  echo -en "Quantity:"
  read Quantity
  Date_Purchased=$(date +"%d %b %Y")  
  
  echo "${product}:${Unit_Price}:${Quantity}:${Date_Purchased}" >> $POS
}
#i am printing out all the daily sales in a day   print_dtotal
#i am printing out all the grand total sales of all days  print_gtotal
summary_items()
{
  
  print_dtotal
 
  print_gtotal
  
  print_dtotal | sort -f4| while read z
    do
        echo $z | cut -f4 -d' '
        return 0
    done
  echo
  echo -en "Press Enter to continue..."
  read
}
print_dtotal()
{
  count=0
  grep -i : $POS | cut -d: -f4 | sort -u | while read i
    do
        dtotal=0
    grep -i "$i" $POS | while read x
        do
            count=`expr $count + 1`
            temp1=`echo $x | cut -d: -f2 | cut -c2-`
            temp2=`echo $x | cut -d: -f3`
            temp3=`calcu_m $temp1 $temp2`
                        dtotal=`calcu_a $dtotal $temp3`
            n=`num_lines "$i"`
               if [ "${n}" -eq "${count}" ]; then
                echo  $i"        $"$dtotal
              fi
        done
    done 
}
print_gtotal()
{
  gtotal=0
  grep -i : $POS | while read x
    do
        temp1=`echo $x | cut -d: -f2 | cut -c2-`
        temp2=`echo $x | cut -d: -f3`
        temp3=`calcu_m $temp1 $temp2`
                gtotal=`calcu_a $gtotal $temp3`
        n=`num_lines "$i"`
           if [ "${n}" -eq "${count}" ]; then
            echo  "Grand Total      $"$gtotal
          fi
        count=`expr $count + 1`
    done 
}
calcu_a()        # add 2 decimal numbers $1 $2
{
    x1=`echo $1 | cut -d. -f1`
    x2=`echo $1 | cut -d. -f2`
    y1=`echo $2 | cut -d. -f1`
    y2=`echo $2 | cut -d. -f2`
    x1=`expr $x1 + $y1`
    x2=`expr $x2 + $y2`
    x3=`expr $x2 \/ 100`
    x1=`expr $x1 + $x3`
    x2=`expr $x2 \% 100`
    echo $x1"."$x2
}
calcu_m()        # multiply 2 decimal numbers $1 $2
{
    x1=`echo $1 | cut -d. -f1`
    x2=`echo $1 | cut -d. -f2`
    y=`echo $2`
    x1=`expr $x1 \* $y`
    x2=`expr $x2 \* $y`
    x3=`expr $x2 \/ 100`
    x1=`expr $x1 + $x3`
    x2=`expr $x2 \% 100`
    echo $x1"."$x2
}

  #4 (permalänk)  
Old 04-22-2009
giannicello giannicello is offline
Registered User
  
 

Join Date: Sep 2001
Ort: Phoenix
Inlägg: 169
Så alla andra funktioner köra fina utom summary_items () funktion? Jag är inte klar på vad felet är det du ser.
  #5 (permalänk)  
Old 04-22-2009
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmerare, författare
  
 

Join Date: mars 2007
Ort: Toronto, Kanada
Inlägg: 2361
Citat:
Ursprungligen postat av xiaojesus View Post
Hej alla Jag har ett manus, men jag skränande lägga upp den sammanfattande rapporten .. hålla med synax fel. åtanke att hjälpa mig att ta en titt och berätta vad som gick fel ..

Jag vet är lite lång, men jag hoppas någon kan Hep mig med det. tack

felmeddelandet kommer upp när jag försöker köra den sammanfattande rapporten ..

Vilket fel får du?

Är det: typ: invalid option - 4
Citat:

Jag antar att 1 av problemet är det system date.thing.

problemet handlar om i butikerna.

Jag försöker att lägga upp alla dagliga försäljningen och sedan har en totalsumman av all försäljning av alla dagar.
nedan är koden.



Kod:
# Global variables
POS=~/.Point_Of_Sales
POS=POS.txt

Du är anvisa två olika värden för POS, bara de senaste uppdraget varar, och det första kan lika gärna aldrig har gjorts.
Citat:

Kod:
export POS

confirm()
{
  echo -en "$@"
  read ans
  ans=`echo $ans | tr '[a-z]' '[A-Z]'`
  if [ "$ans" == "Y" ]; then
    return 0
  else
    return 1
  fi
}

Undvik alternativ till eko, de är icke-standard som är \u003d\u003d.

Du behöver inte ringa tr, kan du kontrollera svaret utan den:


Kod:
confirm()
{
  printf "%s " "$*"
  read ans
  case "$ans" in
    [Yy]) true ;;
    *) false ;;
  esac
}

Citat:

Kod:
num_lines()
{
  grep -i "$@" $POS|wc -l| awk '{ print $1 }'
}

Det kommer att misslyckas om det finns fler än ett argument.

Det finns inget behov av awk eller wc:


Kod:
  grep -ni "$1" "$POS"

Citat:

Kod:
find_lines()
{
  # Find lines matching $1
  res=-1
  if [ ! -z "$1" ]; then
    grep -i "$@" $POS
    res=$?
  fi
  return $res
}

Kod:
find_lines()
{
  # Find lines matching $1
  if [ -n "$1" ]; then
    grep -i "$1" "$POS"
  fi
}

Citat:

Kod:
...
locate_single_item()
{
  echo -en "Item to search for: "
  read search
  n=`num_lines "$search"`
  if [ -z "$n" ]; then
    n=0
  fi
  while [ "${n}" -ne "1" ]; do
    #list_items "$search"
    echo -en "${n} matches found. Please choose a "
    case "$n" in 
      "0") echo "less" ;;
      "*") echo "more" ;;
    esac
    echo "specific search term (q to return to menu): "
    read search
    if [ "$search" == "q" ]; then
      return 0
    fi
    n=`num_lines "$search"`
  done
  return `grep -in $search $POS |cut -d":" -f1`

Det finns inget behov av cut:


Kod:
return `grep -hin $search $POS`

Citat:

Kod:
}

...
summary_items()
{
  #echo "- - - POS Summary Report - - -"
  #echo "---------------------------"
  #echo "Date       Total POS"
  #echo "---------------------------"
  print_dtotal
  #echo "---------------------------"
  #print_gtotal
  #echo "---------------------------"
  #echo -en "Best Selling Product: "
  #print_bestsell
  #echo -en "Product with Highest POS: "
  #print_phighPOS
  #echo -en "Date with Highest POS: "
  print_dtotal | sort -f4| while read z


Kod:
sort: invalid option -- 4

Citat:

Kod:
    do
        echo $z | cut -f4 -d' '
        return 0
    done
  echo
  echo -en "Press Enter to continue..."
  read
}
...
  #6 (permalänk)  
Old 04-22-2009
xiaojesus xiaojesus is offline
Registered User
  
 

Join Date: april 2009
Inlägg: 20
ya alla andra funktionen fungerar bra förutom den sammanfattande del .. någon kan hjälpa mig med det?
  #7 (permalänk)  
Old 04-22-2009
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmerare, författare
  
 

Join Date: mars 2007
Ort: Toronto, Kanada
Inlägg: 2361

Nej, inte om du inte svarar på de frågor du har ställt.
Closed Thread

Komihåglista

Thread Tools Sök i denna tråd
Sök i denna tråd:

Avancerad sökning
Visningslägen Betygsätt denna tråd
Betygsätt denna tråd:

Utstationering Regler
Du får inte efter nya trådar
Du får inte efter svar
Du får inte skicka bilagor
Du får inte redigera dina inlägg

BB-kod är
Smilies är
[IMG] kod
HTML-koden är Av
Trackback är
Pingbacks är
Refbacks är




Alla tider är GMT -4. Klockan är nu 05:12.


Powered by: vBulletin, Copyright © 2000 - 2006, Jelsoft Enterprises Limited. Översättningar Powered by .
vBCredits v1.4 Copyright © 2007 - 2008, PixelFX Studios
UNIX och Linux Forum Innehållet upphovsrättsskyddat © 1993-2009. All Rights Reserved.Ad förvaltning RedTyger

Content Relevant webbadresser från vBSEO 3.2.0