下午好,
我正在尝试制作一个清除一些数据输出文件的bash脚本.文件看起来像这样:
/path/
/path/to
/path/to/keep
/another/
/another/path/
/another/path/to
/another/path/to/keep
Run Code Online (Sandbox Code Playgroud)
我想最终得到这个:
/path/to/keep
/another/path/to/keep
Run Code Online (Sandbox Code Playgroud)
我想循环遍历文件的行,检查下一行以查看它是否包含当前行,如果是,则从文件中删除当前行.这是我的代码:
for LINE in $(cat bbutters_data2.txt)
do
grep -A1 ${LINE} bbutters_data2.txt
if [ $? -eq 0 ]
then
sed -i '/${LINE}/d' ./bbutters_data2.txt
fi
done
Run Code Online (Sandbox Code Playgroud) bash ×1