![]() |
|
|
Googleのunix.com
|
|||||||
| シェルプログラミングとスクリプティング KSH 、 CSH 、 shに、 bashの、はPerl 、 PHPは、削除するsed 、 Awkの、他のシェルスクリプトやシェルスクリプト言語についての質問の投稿はこちら。 |
その他のUNIXおよびLinuxフォーラムトピックは参考にすること
|
||||
| スレッド | スレッドスターター | フォーラム | 返信 | 最後の投稿 |
| Perlの構文解析に比べて解析Ksh | ポパイ | シェルプログラミングとスクリプティング | 1 | 2008年8月6日 11:46午後 |
| kshでのファイルからペアで読んで行 | ytokar | シェルプログラミングとスクリプティング | 4 | 2008年2月8日 02:50午後 |
| perlの検索と置換のペア | umen | シェルプログラミングとスクリプティング | 1 | 2006年7月30日 12:37午後 |
| procに | bache_gowda | UNIXのダミー質問と回答のため | 7 | 2005年5月23日 12:18午後 |
| /procに | aojmoj | UNIXの詳細&エキスパートのためのユーザー | 3 | 2002年11月20日 05:54午後 |
![]() |
|
|
LinkBack | スレッドツール | このスレッドを検索 | スレッドを評価 | 表示モード |
|
|
|
||||
|
こんにちはすべて、 私を使っていくつかの助けが必要 セッド/Awkの/他のLinuxツールは、次の目標を満たすために: 私に/ proc /ネットは/ devの出力をしようとしている: コード:
Inter-| Receive | Transmit
face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
lo:18748525 129811 0 0 0 0 0 0 18748525 129811 0 0 0 0 0 0
eth0:1699369069 226296437 0 0 0 0 0 3555 4118745424 194001149 0 0 0 0 0 0
eth1: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
sit0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
...のインターフェイス( eth0 )はgrepし、次のデータに変える: コード:
rxbytes:1699369069 rxpackets:226296437 rxerrs:0 rxdrop:0 rxfifo:0 rxframe:0 rxcompressed:0 rxmulticast:3555 \ txbytes:4118745424 txpackets:194001149 txerrs:0 txdrop:0 txfifo:0 txcolls:0 txcarrier:0 txcompressed:0 私の所まで行ってきたこの断片は: コード:
cat /proc/net/dev | egrep "(eth0|face)" | sed -e 's/|/:/' | sed -e 's/|/ /' | cut -d ":" -f 2 | tr -s " " " " bytes packets errs drop fifo frame compressed multicast bytes packets errs drop fifo colls carrier compressed 1709184740 226328683 0 0 0 0 0 3555 4122564415 194035769 0 0 0 0 0 0 ...しかし私は、ここから、または続行する場合にも、正しい方向であることがよく分かりません。誰の前に何か似ている(キー:値のペアの列に転換)つまり? あなたの専門知識を、深く感謝です! アップデート:私はどのように行列が分かってきたトランスポーズ(これは一歩近づいています! ) : コード:
cat /proc/net/dev | egrep "(eth0|face)" | sed -e 's/|/:/' | sed -e 's/|/ /' | cut -d ":" -f 2 | tr -s " " " " | \
awk 'BEGIN {FS=" "} {for (i=1;i<=NF;i++){ arr[NR,i]=$i; if(big <= NF) big=NF; }} \
END {for(i=1;i<=big;i++){for(j=1;j<=NR;j++){printf("%s:",arr[j,i]);}printf("\n");}}'
bytes:1718395341:
packets:226353349:
errs:0:
drop:0:
fifo:0:
frame:0:
compressed:0:
multicast:3555:
bytes:4126856358:
packets:194063589:
errs:0:
drop:0:
fifo:0:
colls:0:
carrier:0:
compressed:0:
今私はどのように' 、テキサス州'と' Rxの'前にして、 '末尾: 'と私のすべての設定だストリップを把握する必要があります!このフォーラムで素晴らしいです。 アップデート2 : 私はそのとおり!唯一の方法は、それを改善できるCamelCase ( RxBytes等)があります: コード:
cat /proc/net/dev | egrep "(eth0|face)" | sed -e 's/|/:/' -e 's/|/ /' | cut -d ":" -f 2 | tr -s " " " " | \
awk 'BEGIN {FS=" "} {for (i=1;i<=NF;i++){ if(i<9){arr[NR,i]="rx"$i;}else{arr[NR,i]="tx"$i;} if(big <= NF) big=NF; }} \
END {for(i=1;i<=big;i++){for(j=1;j<=NR;j++){ printf("%s\t",arr[j,i]);}printf("\n");}}' | sed -e 's/\t$//' -e 's/\t/:/' -e 's/:[tr]x/:/'
rxbytes:1790844622
rxpackets:226585666
rxerrs:0
rxdrop:0
rxfifo:0
rxframe:0
rxcompressed:0
rxmulticast:3555
txbytes:4161116750
txpackets:194310608
txerrs:0
txdrop:0
txfifo:0
txcolls:0
txcarrier:0
txcompressed:0
複数行の形式は、実際には自分のアプリケーションで動作します。 編集otheusで最終; 2009年1月30日に 07:31午前..理由: Woot ! |