这是由其他人编写的 AppleScript 创建的简短文本文件的内容:
Search time: Sunday April 28, 2019 at 07:21:07
Search complete. Nothing found.
但是,当我使用 cat 时,我得到以下信息:
MrMuscle:bin mnewman$ cat /Users/mnewman/Desktop/DetectX_Search.txt
MrMuscle:bin mnewman$ ng found.019 at 07:21:07
当我在 BBEdit 中查看文件并打开“显示不可见内容”时,我只看到空格和换行符。
该文件在 nano 中看起来很正常。
我想将文件的第一行读入变量但没有任何效果:
MrMuscle:bin mnewman$ read -r growlm < /Users/mnewman/Desktop/DetectX_Search.txt
MrMuscle:bin mnewman$ echo $growlm
Search complete. Nothing found.2019 at 07:21:07
MrMuscle:bin mnewman$ growlm="$(head -1 /Users/mnewman/Desktop/DetectX_Search.txt)"
MrMuscle:bin mnewman$ echo $growlm
Search complete. Nothing found.2019 at 07:21:07
MrMuscle:bin mnewman$ file /Users/mnewman/Desktop/DetectX_Search.txt
/Users/mnewman/Desktop/DetectX_Search.txt: ASCII text, with CR line terminators
MrMuscle:bin mnewman$ cat /Users/mnewman/Desktop/DetectX_Search.txt | od -c
0000000 S e a r c h t i m e : S u n
0000020 d a y , A p r i l 2 8 , 2
0000040 0 1 9 a t 0 9 : 3 9 : 1 7 \r
0000060 S e a r c h c o m p l e t e .
0000100 N o t h i n g f o u n d . \r
0000120
答案1
以下是有效的方法:
cat DetectX_Search.txt | tr '\r' '\n' > DetectX.txt
MrMuscle:bin mnewman$ cat DetectX.txt
Search time: Sunday, April 28, 2019 at 10:40:35
Search complete. Nothing found.