[英]generate a .tab file with filenames and paths separated by tab
I have just started learning linux CLI.我刚刚开始学习 linux CLI。 I am using snippy tool for comparing multiple files that require a .tab format file.我正在使用 snippy 工具来比较需要 .tab 格式文件的多个文件。 This tab formatted file should be consisting of the paths and filenames separated by tab (\\t).此制表符格式的文件应由以制表符 (\\t) 分隔的路径和文件名组成。
I have run this two commands separately to generate a list of filenames and paths.我分别运行了这两个命令以生成文件名和路径列表。
find $(pwd)/*.fna > /home/fan/onas/filenames.tab
and和
ls > filenames.tab
but whenever I run this command to check the tabs in file.但是每当我运行此命令来检查文件中的选项卡时。 There is no tab (\\t) exists inside the file.文件中不存在制表符 (\\t)。
cat -vet filenames.tab
I have used also this command to replace the \\n with \\t.我也使用此命令将 \\n 替换为 \\t。 But it doesn't work here.但它在这里不起作用。
sed 's/\n/\t/g' filenames.tab > file2.tab
In short, I'm trying to generate a file having filenames and paths separated by tabs or .tab format.简而言之,我正在尝试生成一个文件,其文件名和路径由制表符或 .tab 格式分隔。 Could somebody help me with this?有人可以帮我解决这个问题吗? Thanks谢谢
The command printf
...命令printf
...
printf "%s\t" $(ls -A $(pwd)) >files.tab
...formating output of ls -A
(also hidden files) separated with tabs to ( >
) files.tab. ...格式化ls -A
(也是隐藏文件)的输出,用制表符分隔到 ( >
) files.tab。
If your
printf
also supports-v
then you can do...如果你的printf
也支持-v
那么你可以做...
printf -v FILES "%s\t" $(ls -A $(pwd))
echo ${FILES}
But the tabs sadly get lost.但可悲的是标签丢失了。 Writing it to a file like in the first example corrects it...将它写入一个文件,就像第一个例子一样纠正它......
printf "%s\t" ${FILES} >files.tab
Wonder why only one %s\\t
?想知道为什么只有一个%s\\t
? Hm, its like a foreach
on an array.嗯,它就像一个数组上的foreach
。 For each element in the whitespace separated list printf
do the %s\\t
and throws other whitespace away.对于空格分隔列表printf
中的每个元素,执行%s\\t
并丢弃其他空格。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.