【发布时间】:2019-01-31 09:40:13
【问题描述】:
我有一个名为 input.txt 的输入文件,如下所示:
powerOf|creating new file|failure
creatEd|new file creating|failure
powerAp|powerof server|failureof file
我将文本提取到第一个字段中第一个大写字母之前的文本,并将这些 sn-ps 存储在output.txt:
power
creat
我使用sed 命令分离出值,它工作正常。
从输出文件(output.txt),我需要从第一个字段grep,输出应该如下所示:
Power
power:powerOf|creating new file|failure,powerAp|powerof server|failureof file
creat
creat:creatEd|new file creating|failure
我尝试了几种方法,但没有得到预期的输出。
我尝试了以下方法,但出现重复条目:
cat input.txt | cut -d '|' f1 >> input1.txt
cat input1.txt | s/\([a-z]\)\([A-Z]\)/\1 \2/g >> output.txt
while read -r line;do
echo $ line
cat input.txt |cut -d ‘|’ f1|grep $line >> output1. txt
done< "output.txt"
我在输入文件中有 20000 行。我不知道为什么我得到重复的输出。我做错了什么?
【问题讨论】:
-
我关闭了 the old question 作为这个的副本。