从文件中获取特定字符串

Get a specific string from a file

我有一个以这种格式开头的文件

INFO|NOT-CLONED|/folder/another-folder/another-folder2|last-folder-name|

我需要的是读取文件并得到这个输出:

another-folder

到目前为止我有这个:

sed -En 's/(INFO\|NOT-CLONED\|).*\|([^|]*)\|$//p'"

但没有按预期工作。

awk -F'/' '/INFO\|NOT-CLONED/{print }' file

或者如果你想使用 sed :

sed  -n 's@INFO|NOT-CLONED|/[^/]\+/\([^/]\+\).*@@gp' file