【发布时间】:2013-05-25 21:58:50
【问题描述】:
我有一个正在逐行读取的日志文件。
可能的输入:
" 0:00 InitAuth: \auth\0\auth_status\init\auth_cheaters\1\auth_tags\1\auth_notoriety\1\auth_groups\ \auth_owners"
想要的输出:
$TIME = 0:00
$TYPE = InitAuth:
$DATA = \auth\0\auth_status\init\auth_cheaters\1\auth_tags\1\auth_notoriety\1\auth_groups\ \auth_owners
或$Output[0]、$Output[1]、$Output[2] 我不在乎它是 1 个数组还是 3 个变量。
起初我在考虑将该行拆分为 3 个变量并使用分隔符之类的空格,所以我试图搜索 sh 替换 PHP 命令 explode(' ', $input, 3); 但后来我找到了这样的行:
"1728:32ClientUserinfoChanged: 0 n\ThunderBird\t\3\r\2\tl\0\f0\ \f1\ \f2\ \a0\0\a1\0\a2\0"
$TIME = 1728:32
$TYPE = ClientUserinfoChanged:
$DATA = 0 n\ThunderBird\t\3\r\2\tl\0\f0\ \f1\ \f2\ \a0\0\a1
时间和类型信息之间没有空格。 所以我想知道,我现在应该如何拆分该文本?
我也是 Shell 新手,我正在谷歌搜索所有可能的命令。
【问题讨论】:
-
我的一个“linux”朋友正在帮我解决这个问题,他给我发了这个:output=
echo $input | sed 's/^[^:]*:.. \?//'但它只会输出类型和数据并忽略/跳过时间。
标签: string shell split explode