新文件中每个文件的第一行

use*_*003 1 bash shell scripting file line

如何在目录中获取每个文件的第一行并将它们全部保存在新文件中?

#!/bin/bash

rm FIRSTLINE
for file in "$(find $1 -type f)";
do
head -1 $file >> FIRSTLINE
done
cat FIRSTLINE
Run Code Online (Sandbox Code Playgroud)

这是我的bash脚本,但当我这样做并打开文件FIRSTLINE时,我看到了这个:

==> 'path of the file' <==
'first line' of the file
Run Code Online (Sandbox Code Playgroud)

这对我论证中的所有文件都有用.

有人有解决方案吗?

Zso*_*kai 5

find . -type f -exec head -1 \{\} \; > YOURFILE
Run Code Online (Sandbox Code Playgroud)

可能适合你.