bash - 生成特殊文件列表

标签 bash list awk ffmpeg

如何在 bash 中获得这样的列表:
我必须创建一个这样的列表,然后连接 ffmpeg 的文件。

ls -l stream
-rw-r - r-- 1 root root 0 Nov 9 20:30 Il.Gatto.Nero.2019.mp4
-rw-r - r-- 1 root root 0 Nov 9 20:30 My.Name.2019.mp4
-rw-r - r-- 1 root root 0 Nov 9 20:30 Terminator.2019.mp4
-rw-r - r-- 1 root root 0 Nov 9 20:30 spot-Il.Gatto.Nero.2019.mp4
-rw-r - r-- 1 root root 0 Nov 9 20:30 spot-My.Name.2019.mp4
-rw-r - r-- 1 root root 0 Nov 9 20:30 spot-Terminator.2019.mp4

i need to create a txt file like this:

file '/stream/spot-Il.Gatto.Nero.2019.mp4'
file '/stream/Il.Gatto.Nero.2019.mp4'
file '/stream/spot-Terminator.2019.mp4'
file '/stream/Terminator.2019.mp4'
file '/stream/spot-My.Name.2019.mp4'
file '/stream/My.Name.2019.mp4'
file ..........



ls -l | awk {'print "file \047/data/"$9 "\047" '} | awk NF
file '/data/'
file '/data/Il.Gatto.Nero.2019.mp4'
file '/data/Il.Mio.Nome.2019.mp4'
file '/data/Terminator.2019.mp4'
file '/data/spot-Il.Gatto.Nero.2019.mp4'
file '/data/spot-Il.Mio.Nome.2019.mp4'
file '/data/spot-Terminator.2019.mp4'
问候密歇根
在 php 中有这样写:
<?php
$db_host = 'localhost';
$db_name = 'genlist';
$db_user = '********';
$db_pass = '********';
$conn = mysqli_connect($db_host, $db_user, $db_pass);

if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
} else {
//echo "Connected successfully";
}
mysqli_select_db($conn,$db_name) or die ("Error select db: " . mysqli_error());

$sql = "SELECT * FROM tb_movie ORDER BY RAND()";
$query = mysqli_query($conn,$sql);

while($result = mysqli_fetch_assoc($query)) {

$data = "file '/data/EagleCinema/CinemaDramaNew/stream/" . $result['spot']  . "'"."\n";
$data .= "file '/data/EagleCinema/CinemaDramaNew/stream/" . $result['movie'] . "'"."\n";

file_put_contents('/var/www/html/random-cinema-drama.txt', $data, FILE_APPEND );

}


?>
php结果:
file '/data/EagleCinema/CinemaDramaNew/stream/spot-Demolition.-.Amare.E.Vivere.2015.mp4'
file '/data/EagleCinema/CinemaDramaNew/stream/Demolition.-.Amare.E.Vivere.2015.mp4'
file '/data/EagleCinema/CinemaDramaNew/stream/spot-Una.Giusta.Causa.2018.mp4'
file '/data/EagleCinema/CinemaDramaNew/stream/Una.Giusta.Causa.2018.mp4'
file '/data/EagleCinema/CinemaDramaNew/stream/spot-Io.Prima.Di.Te.2016.mp4'
file '/data/EagleCinema/CinemaDramaNew/stream/Io.Prima.Di.Te.2016.mp4'
file '/data/EagleCinema/CinemaDramaNew/stream/spot-A.Beautiful.Day.2017.mp4'
file '/data/EagleCinema/CinemaDramaNew/stream/A.Beautiful.Day.2017.mp4'
file '/data/EagleCinema/CinemaDramaNew/stream/spot-Un.Improbabile.Amicizia.2019.mp4'
file '/data/EagleCinema/CinemaDramaNew/stream/Un.Improbabile.Amicizia.2019.mp4'
file '/data/EagleCinema/CinemaDramaNew/stream/spot-The.Intervention.2016.mp4'
file '/data/EagleCinema/CinemaDramaNew/stream/The.Intervention.2016.mp4'
...
我需要相同的结果,但使用 bash 脚本没有 DB,只从目录中扫描文件并生成列表。

最佳答案

可以格式化 find 的输出像这样的命令:

find . -printf "file '%p'\n"
阅读有关 find 的更多信息命令及其格式化选项here .
样本输出:
file './tomcat-docbase.8602702943778820035.8020'
file './tomcat.7980157961655295062.8020'
file './tomcat.7980157961655295062.8020/work'
file './tomcat.7980157961655295062.8020/work/Tomcat'
file './tomcat.7980157961655295062.8020/work/Tomcat/localhost'
file './tomcat.7980157961655295062.8020/work/Tomcat/localhost/ROOT'
file './tomcat-docbase.7948873979763860512.8020'
file './metadata'
file './chrome-win.zip'

关于bash - 生成特殊文件列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64758255/

相关文章:

linux - 从字符串中删除一个字符

java - 尝试将列表转换为数组时出错 []

linux - Grep 命令需要解释

linux - 在 Bash 中处理 float

linux - 找到直方图的最小值

linux - Bash 脚本 - 将文件的最后一行复制到另一个文件

linux - 通过匹配从另一个文件获得的模式替换文件中的字符串

mysql - 在同一 mysql session 中具有多个查询和重定向的 Bash 脚本

python - 如何查找存在于两个列表中但具有不同索引的元素

python - 如何从Python中的循环创建可变矩阵列表?