![]() |
|
|
Googleのunix.com
|
|||||||
| シェルプログラミングとスクリプティング KSH 、 CSH 、 shに、 bashの、はPerl 、 PHPは、削除するsed 、 Awkの、他のシェルスクリプトやシェルスクリプト言語についての質問の投稿はこちら。 |
その他のUNIXおよびLinuxフォーラムトピックは参考にすること
|
||||
| スレッド | スレッドスターター | フォーラム | 返信 | 最後の投稿 |
| awkは複数のフィールド区切り? (最初にスペースをして、結腸) | doubleminus | UNIXのダミー質問と回答のため | 3 | 2008年4月27日 04:28午後 |
| 私が必要とするフィールドとフィールドのセパレータを使用してカウントの仕方Nawk | scrappycc | シェルプログラミングとスクリプティング | 3 | 2008年2月6日 11:47午後 |
| 入力に対して、複数のファイルをリダイレクトすることができますか? | Matrix_Prime | UNIXのダミー質問と回答のため | 4 | 2005年2月27日 07:07午後 |
| Awkの複数のフィールドの区切り | Tonka52 | シェルプログラミングとスクリプティング | 7 | 2004年4月7日 10:37午後 |
| 出力は複数のフィールドのデータベースファイルから | Dennz | UNIXのダミー質問と回答のため | 3 | 2003年9月1日 01:41午後 |
![]() |
|
|
LinkBack | スレッドツール | このスレッドを検索 | スレッドを評価 | 表示モード |
|
|
|
||||
|
私はここawkはどのように複数の入力フィールド区切り文字を処理するの記事を参照のカップルを見た。私がどれ(だけ! )どのようにログファイルに以下の行を共有する方法を考え出したと思いました:
D1111111111111111 @ 90000000000000000000010001名D0.90000000000103787900010001QF840840916070000007085814Y216254 \u003d 1107xxxxxxxxxxxxxxx x919MENCHIES この形式に: 90000000000000000000010001 、名前、 840840916070000007085814Y216654 、 1111111111111111,1107,919 MENCHIES 以来、この有用な情報をログ転換の過程で1つのステップである私は、全体のスクリプトがあるが、関連性の高い部分heres 。 #著者: kinksville #日: 2008年4月24日 #改訂: 2008年4月24日 #リビジョン:リビジョン1.00 #その他のファイル: cclookup.s 、 cclookup.rep #変更履歴: # 2008年4月24日:このスクリプトの作成頭文字。 # #エンドの変更履歴。 開始( のFS \u003d " [ \ 。 QF \ @エ\u003d x ]は+ " OFS \u003d " 、 " ) #最初の繰り返しは、 D @検索、を除去。文字を挿入するOFS 。 のD / \ @ / ( #任意の文字列@ D線を含むページの検索 report2 \u003d " cclookup.rep2 " ; report2変数を定義# 。 報告書\u003d " cclookup.rep " ;レポート変数を定義# 。 num_cclookup + + ;認証リクエストの数を取得# 。 印刷$ 1 、 $ 2 、 $ 5 、 $ 6 、 $ 7 、 $ 8 >レポート; $ 0印刷> report2 ; D検索@ ) #終了。 このキーは、実際のファイルの区切り文字としては、 Awkの正規表現を受け入れるということです。この正規表現のFS \u003d " [ \ 。 QF \ @エ\u003d x ]は+ "スペースは、一致しています。 QFは、文字列、エ@という文字列は、 \u003d 、および文字のXのブラケットの+の後に後続の鍵、それ以降のいずれかの文字は、正規表現にマッチの1つまたは複数のインスタンスを可能にしています。 つまり、 xとがXXXXXXの両方を1つのフィールド区切り文字として扱われます。 私はまだその出力で動作するように、今から私は、最後のフィールドの最後に名前を調整する必要がある必要があります。残念ながら最後のフィールドには、コードのどこ9999999 1の範囲内のこととは、部分は、私を維持したいです。たぶん、 [ ^ 0-9 ] +表現? |
|
||||
|
そうは問屋が卸さない
引用:
![]() 私にとってもそれらの断片が正しく働いた。ののFSの構文は、おそらく、フィールドの数が変更されましたので、すべての出力を取得できませんでした使用されます。 2番目の断片だけを追加するように# 1の最後のフィールドすなわち( 619MENCHIES1 ) 。 私はそれをいくつかと何が起こるのかを参照してください再生されます。 |
|
||||
|
コード:
#This script scans the appropriate log file and copies lines containing authorization requests to the output.
#All output is comma separated.
#Author: kinksville
#Date: April 24, 2008
#Revised: April 25, 2008
#Revision: Revision 1.01
#Other files: cclookup.s, cclookup.rep
#Changelog:
#April 24, 2008: Initial creation of the script.
#April 25, 2008: Updated the regex for the input FS to match multiple characters.
#
#End changelog.
BEGIN {
#Input field separators will match any of the following characters/strings: blank space, . , QF, @D, =, x (repeating).
#The + on the outside of the brackets will allow it to match 0 or more instances of any of the characters/strings in any combination.
#% Any comments with the % sign are temporarily there for testing purposes.
FS="[ \. QF \@D = x]+"
#Output field separator is defined as a comma.
OFS = ","
}
#@D search, stripping out the field separator characters and inserting a OFS.
/\@D/ { #Search for any line containing the string @D
last_field=$8 ;
sub(/[^0-9]*/,"",last_field );
dollar_val=last_field/100 ;
report="cclookup.rep"; #Define report variable.
num_cclookup++; #Get number of auth requests.
field1=$1 ;
field2=$2 ;
field3=$5 ;
field4=$6 ;
field5=$7 ;
printf ("%s,%s,%s,%s,%s,$%-.2f\n",field1,field2,field3,field4,field5,dollar_val) > report
#print $1, $2, $5, $6, $7, $8 > report; #Print fields 1-2 with the OFS between them to report.
} #End of the @D search.
これはやり方のまずいコーディングのはちょっと大変だが、動作します。私はプレーンの印刷コマンドを使用していたが、なぜ私は最終的に行ったprintfの代わりにしても、プリントアウトしているようだlast_field変数を取得できませんでした。私にも出力に許可する前に、これらの数字からMENCHIESされた金額を10進形式での結果。 編集kinksvilleで最終; 2008年4月25日に 06:13午後..理由:コメント欄から削除フルネーム。 |