我在使用本网站上提供的答案时遇到了一些问题,该问题是关于 sed 命令用另外两行内容替换空行的,如果 Mac OS 上的 sed 命令(对我来说是 10.6.7) ) 是不同的。我不认为是这样,但想知道这个网站上的其他人是否有不同的想法。
我YYYYMMDD在文件名中有一个名为 with的文件,例如
file-name-20151002.txt
Run Code Online (Sandbox Code Playgroud)
我想确定这个文件是否在 2015-10-02 之后被修改过。
ls,但我知道解析 的输出ls是一个坏主意。20151002名称中的文件是否在 2015 年 10 月 3 日或之后被修改过。我想排序
下列
cat /tmp/foo.txt | sort -t/ -k3,3 -k3,3n
Run Code Online (Sandbox Code Playgroud)
完成 1,但未完成 2。
/tmp/foo.txtdirA/catA/apple.txt
dirA/catA/addition.txt
dirA/catA/difference
dirA/catB/binary.txt
dirA/catB/carry.txt
dirA/catB/digit
dirA/catC/test-10.txt
dirA/catC/test-100.txt
dirA/catC/test-1000.txt
dirA/catC/test-11.txt
dirA/catC/test-2.txt
dirA/catC/test-20.txt
dirA/catC/test-25.txt
dirA/catC/test-5.txt
dirA/catC/test-50.txt
dirA/catC/test-500.txt
dirA/catC/test-7.txt
dirA/catC/test-75.txt
dirA/catC/test-8.txt
dirA/catC/abc-test-9.txt
dirA/catC/abc-test-999.txt
dirA/catC/abc-test-75.txt
dirA/catC/abc-test-8.txt
Run Code Online (Sandbox Code Playgroud)
dirA/catC/abc-test-8.txt
dirA/catC/abc-test-9.txt
dirA/catC/abc-test-75.txt
dirA/catC/abc-test-999.txt
dirA/catA/addition.txt
dirA/catA/apple.txt
dirA/catB/binary.txt
dirA/catB/carry.txt
dirA/catA/difference
dirA/catB/digit
dirA/catC/test-2.txt
dirA/catC/test-5.txt
dirA/catC/test-7.txt
dirA/catC/test-8.txt
dirA/catC/test-10.txt
dirA/catC/test-11.txt
dirA/catC/test-20.txt
dirA/catC/test-25.txt
dirA/catC/test-50.txt
dirA/catC/test-75.txt
dirA/catC/test-100.txt
dirA/catC/test-500.txt
dirA/catC/test-1000.txt
Run Code Online (Sandbox Code Playgroud) 出于性能原因,我想用来find列出大量文件,但也在每行上包含一个计数器。以下是我到目前为止所拥有的:
local root_dir="."
local ouptut_file="/tmp/foo.txt"
File_Number=99 ## Initial value
echo "" > "${ouptut_file}" ## Initialize file to empty
find "$root_dir" \
-type f \
-depth 2 \
-name '*.xxx' \
-print0 \
| sort -z \
| xargs -0 printf "DoSomething %5d '%s'\n" $[File_Number++] -- \
> "${ouptut_file}"
Run Code Online (Sandbox Code Playgroud)
这输出
DoSomething 99 '--'
DoSomething 0 'dirA/dirB/file1.xxx'
DoSomething 0 'dirA/dirB/file2.xxx'
DoSomething 0 'dirA/dirB/file3.xxx'
Run Code Online (Sandbox Code Playgroud)
我想要的是
DoSomething 100 'dirA/dirB/file1.xxx'
DoSomething 101 'dirA/dirB/file2.xxx'
DoSomething 102 'dirA/dirB/file3.xxx'
Run Code Online (Sandbox Code Playgroud)
如何包含计数器并消除输出中的第一个杂散线。
系统bash:正在macOS Ventura 13.0.1 上使用
如何让 unix 命令的某些选项来自文件?这是该文件确实不包含所有的选项-其他选项另行规定。
例如,我有lsoptions.txt包含以下内容的文件:
-F -G
Run Code Online (Sandbox Code Playgroud)
现在我想执行
ls -a <and all options specified in the file lsoptons.txt>
Run Code Online (Sandbox Code Playgroud)
即,我想执行ls -a -F -G.
也就是说,指定一些选项,但其他选项是从文件中读取的。
TeX文件中提供的参数。因此,我不会让用户在多个位置复制信息,而是将TeX所需的选项写入文件,以便 shell 脚本也可以访问它们。一种选择是TeX生成整个脚本,但如果我可以从文件中读取选项会容易得多。