【发布时间】:2016-02-10 21:27:03
【问题描述】:
我有一个脚本,可以格式化一些难以阅读的日志文件的输出,以使它们易于阅读。我按如下方式调用我的脚本
me@myHost $ cat superBigLogFile$date | grep "Stuff from log file I want to see" | /scripts/logFileFormatter
在脚本内部,它使用了 $0、$1 和 $2,但我不知道 cat'ed 文本映射到哪个参数。我想对脚本进行更改,我只需要输入日期和我想看到的内容。如:
me@myHost $/scripts/logFileFormatter 2016-02-10 "Stuff I want to see"
以下是脚本的详细信息。技术细节是该脚本将 NDM 日志的输出格式化为人类可读的形式。
PATH=/usr/xpg4/bin:/usr/bin
# add SUMM field and end of record marker on stat lines
awk '{print $0"|SUMM=N|EOR"}' |\
# format the STAT file, putting each field on a separate line
tr '|' '\012' |\
# separate times from dates and reformat source and destination file fields
# to have a space after the =
awk -F= '{
if ($1=="DFIL" || $1=="SFIL") print $1 "= " $2
else if ($1=="STAR" || $1=="SSTA" || $1=="STOP" ) {
split($2,A," ")
print $1 "=" A[1] "=" A[2]
}
else print
}' |\
# execute the ndmstat.awk that comes with Connect:Direct
awk -F= -f /cdndm/cmddbp1/cdunix/ndm/bin/ndmstat.awk |\
# additional formatting to remove the greater than sign arrows
sed 's/=>/=/g'
【问题讨论】:
-
$0,$1, 等等...不是外壳。那是awk。 -
不是参数。这是标准输入。
-
这个问题所基于的前提是非常错误的,我不确定它可以简洁地回答。