【发布时间】:2018-04-02 15:21:18
【问题描述】:
我试图让一个 if 语句在 bash 中工作,它处理文本文件中以 \ 开头的行。
类似这样的:
shasum -a 256 file_A\\\\\/\/.txt >> file_B.txt
if line begins with '\' in file_B.txt
then sed 's/^/^.{65} /; s/$/$/' that line in file_C.txt
else
if line not begin with '\' in file_B.txt
then sed 's/^/^.{64} /; s/$/$/' that line in file_C.txt
fi
fi
file_B.txt 的内容:
e5fba57b49dbe8196ee4fb4ddb407885582f88d8e52dfa6e5adb55204b589a88 /Users/1337/file_D.txt
\66590f18dafff57160770d885b090d54455e0fc900342d7752dc420405ae50f5 /Users/1337/file_A\\\\::.txt
file_C.txt的内容:
/Users/1337/file_D.txt
/Users/1337/file_A\\::.txt
所以,基本上,最终结果将如下所示(在 file_C.txt 中):
^.{64} /Users/1337/file_D.txt$
^.{65} /Users/1337/file_A\\::.txt$
因为第 2 行以 \ 开头,而第 1 行没有。
如果其中有任何令人困惑的地方,请随时要求我澄清。
Mac OS X Yosemite,bash 3.2.57(1)-release
【问题讨论】:
标签: bash macos if-statement sed