我想在后面加上一个单词来重复一个单词。 Atm我的bash脚本仅写搜索到的单词,而不写以下几行。 每行以日期开头,但不以以下各行开头。 就我而言,最好用“ cut”选项编写“ while”命令? 我如何使其运行?
read -p "what you want to search?: " Search
grep -i "${Search}" "$1"
2017-03-15 15:23:02,814 ERROR - (8564@xxxxxxx-PC)
java.lang.NoClassDefFoundError: Could not initialize class
at java.util.concurrent.FutureTask$Sync.innerRun
at java.util.concurrent.FutureTask.run
at java.util.concurrent.ThreadPoolExecutor.runWorker java.util.concurrent.ThreadPoolExecutor$Worker.run
at java.lang.Thread.run(Thread.java:722)
at java.lang.Thread.run(Thread.java:722)
at java.lang.Thread.run(Thread.java:722)
at com.xxxxxxx.batch.converter.compart.CompartWrapper.transform
at com.xxxxxxx.batch.converter.compart.CompartWrapper.convert
at com.xxxxxxx.batch.converter.AbstractConverter.run
at com.xxxxxxx.batch.converter.fo.FoConverter.foToFormatUnequalFo
at com.xxxxxxx.batch.converter.fo.FoConverter.convert
at com.xxxxxxx.batch.converter.fo.FoConverter.call
2017-03-15 15:23:02,847 ERROR - (8564@xxxxxxx-PC)
java.lang.NoClassDefFoundError: Could not initialize
at java.util.concurrent.FutureTask$Sync.innerRun
at java.util.concurrent.FutureTask.run
at java.util.concurrent.ThreadPoolExecutor.runWorker
at java.util.concurrent.ThreadPoolExecutor$Worker.run
at java.lang.Thread.run
答案 0 :(得分:0)
$ grep -A1 -i "${Search}" "$1"
“-A1”返回匹配的行,再返回1行。调整数字以适合您的需求。
答案 1 :(得分:0)
2周后,也许我找到了一种在日志文件中进行搜索的方法 但是我需要你的意见
#!/bin/bash -e
if [ -e "$1" ] ;
then
input="$1"
else
echo "need name file after script" >&2
exit
fi
erra() { grep --color -i -n -P "${search}|\t" "$1";}
infa() { grep --color -i -n -P "${search}" "$1";}
searcht() { [[ $search == [eE]* ]];}
searchiw() { [[ $search == [iIwW]* ]];}
conti() { read -r -p "another request?[y/n]: " ans
if [[ $ans == [nN]* ]]
then
exit
fi;}
while :
do
read -r -p "what do you search?: " "search"
if searcht "$1"
then
erra "$1"
conti "$1"
else
searchiw "$1"
infa "$1"
conti "$1"
fi
done