The UNIX and Linux Forums  
Helloやアメリカ合衆国へようこそ! UNIXおよびLinuxフォーラム!訪問し、当社のグローバルコミュニティに参加いただきありがとうございます。

Go Back   UNIXおよびLinuxフォーラム > トップフォーラム > シェルプログラミングとスクリプティング
Googleのunix.com



シェルプログラミングとスクリプティング KSH 、 CSH 、 shに、 bashの、はPerl 、 PHPは、削除するsed 、 Awkの、他のシェルスクリプトやシェルスクリプト言語についての質問の投稿はこちら。

その他のUNIXおよびLinuxフォーラムトピックは参考にすること
スレッド スレッドスターター フォーラム 返信 最後の投稿
オンラインヘルプの概要 uwork72 シェルプログラミングとスクリプティング 4 2008年9月7日 08:56午前
どのように要約する1つのコマンドのCPU使用率ですか? jiarong.lu HP - UX 1 2008年2月22日 11:03午前
積算合計はgrep /複数のファイルを最終的な総 MrAd UNIXのダミー質問と回答のため 5 2007年5月8日 01:03午後
システムの概要ツール vader UNIXのダミー質問と回答のため 2 2002年7月3日 02:28午後

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek を搭載 Powered by Google
 
LinkBack スレッドツール このスレッドを検索 スレッドを評価 表示モード
  #1固定リンク)  
Old 2009年4月22日
xiaojesus xiaojesus is offline
登録ユーザー
  
 

参加日: 2009年4月
投稿: 20
どのように要約レポートに合計を追加するには?

こんにちはすべて私は、スクリプトをしたが、私は要約報告書を追加するカント.. synaxエラーをしている。心を見ていたし、何が間違っ..教えて私を助ける

私の知る少し長いが、私は誰かが私に気付いてできることを願っています。ありがとう

このエラーメッセージは、私..の概要レポートを実行しようとする

私は1この問題は、システムのdate.thing推測されています。

売上高の問題点についてです。

私はすべての毎日の売り上げを追加するとしているすべての日のすべての売上高を合計している。
下のコードです。




コード:
# 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固定リンク)  
Old 2009年4月22日
giannicello giannicello is offline
登録ユーザー
  
 

参加日: 2001年9月
場所:フェニックス
投稿数: 169
何を移動したときに発生するsummary_items ( )上記のprint_dtotal関数( ) ?
  #3固定リンク)  
Old 2009年4月22日
xiaojesus xiaojesus is offline
登録ユーザー
  
 

参加日: 2009年4月
投稿: 20
こんにちはすべて、私は以下のキーにして、システムには、毎日の売上高を入力します。

午前の要約リストを求めるときには毎日の総売上高と売上高は総計すると仮定私
以下に私..書いているのコードですいずれかの手助けすることができますか?

私をsyntaxerror .. doesn'tこの関数は、システム日と見なさいpromt reconiseに適するようだ



コード:
#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固定リンク)  
Old 2009年4月22日
giannicello giannicello is offline
登録ユーザー
  
 

参加日: 2001年9月
場所:フェニックス
投稿数: 169
だから、他のすべての機能を除き、罰金summary_items ( )関数を実行しますか?私はそれを目の当たりにしては何のエラーを明確ではない。
  #5固定リンク)  
Old 2009年4月22日
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
シェルプログラマは、著者
  
 

参加日: 2007年3月
場所:トロント、カナダ
投稿数: 2361
引用:
当初の投稿 xiaojesus View Post
こんにちはすべて私は、スクリプトをしたが、私は要約報告書を追加するカント.. synaxエラーをしている。心を見ていたし、何が間違っ..教えて私を助ける

私の知る少し長いが、私は誰かが私に気付いてできることを願っています。ありがとう

このエラーメッセージは、私..の概要レポートを実行しようとする

どのようなエラーになるのですか?

それは:並べ替え:無効なオプション- 4
引用:

私は1この問題は、システムのdate.thing推測されています。

売上高の問題点についてです。

私はすべての毎日の売り上げを追加するとしているすべての日のすべての売上高を合計している。
下のコードです。


コード:
# Global variables
POS=~/.Point_Of_Sales
POS=POS.txt

あなたが現在、 2つの異なる値を代入しています。耐えるだけの最後の割り当て、最初に行われたことはなかったかもしれない。
引用:
コード:
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
}

を回避するオプションエコー;は非標準的であるとして\u003d\u003d.です

あなたトランジスタを呼び出す必要はありません。あなたがなく、答えを確認することができます:

コード:
confirm()
{
  printf "%s " "$*"
  read ans
  case "$ans" in
    [Yy]) true ;;
    *) false ;;
  esac
}
引用:
コード:
num_lines()
{
  grep -i "$@" $POS|wc -l| awk '{ print $1 }'
}

2つ以上の引数があればそれは失敗します。

Awkのかトイレが必要なのは:

コード:
  grep -ni "$1" "$POS"
引用:
コード:
find_lines()
{
  # Find lines matching $1
  res=-1
  if [ ! -z "$1" ]; then
    grep -i "$@" $POS
    res=$?
  fi
  return $res
}
コード:
find_lines()
{
  # Find lines matching $1
  if [ -n "$1" ]; then
    grep -i "$1" "$POS"
  fi
}
引用:
コード:
...
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`

そこを削減する必要はありません:

コード:
return `grep -hin $search $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

コード:
sort: invalid option -- 4
引用:
コード:
    do
        echo $z | cut -f4 -d' '
        return 0
    done
  echo
  echo -en "Press Enter to continue..."
  read
}
...
  #6固定リンク)  
Old 2009年4月22日
xiaojesus xiaojesus is offline
登録ユーザー
  
 

参加日: 2009年4月
投稿: 20
屋、その他のすべての機能は、要約部分を除いて正常に機能している..いずれかが助けてくれますか?
  #7固定リンク)  
Old 2009年4月22日
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
シェルプログラマは、著者
  
 

参加日: 2007年3月
場所:トロント、カナダ
投稿数: 2361

いいえ、要請されている場合は、質問に答えていないされていません。
Closed Thread

ブックマーク

スレッドツール このスレッドを検索
このスレッドを検索

高度な検索
表示モード このスレッド
このスレッド

投稿ルール
あなた ことができない。 新しいスレッドを投稿
あなた ことができない。 返信の投稿
あなた ことができない。 添付ファイルの投稿
あなた ことができない。 自分の投稿を編集

BBコード なる 〜の上に
スマイリー なる 〜の上に
[イメージ] コードは 〜の上に
HTMLコードは、 オフ
トラックバック なる 〜の上に
ピングバック なる 〜の上に
Refbacks なる 〜の上に




すべてGMT -4です。現在の時刻は 07:12午後


提供: vBulletin、著作権© 2000 - 2006、Jelsoft企業株式会社。言語翻訳による電源
vBCredits v1.4著作権© 2007 - 2008 、 PixelFXスタジオ
は、 UNIXおよびLinuxフォーラムのコンテンツ著作権© 1993 〜 2009 。すべての権利を管理しReserved.Ad RedTyger

コンテンツ関連のURLで vBSEO 3.2.0