我目前正在使用以下命令:
grep -l -Z -E '.*?FindMyRegex' /home/user/folder/*.csv | xargs -0 -I{} mv {} /home/destination/folder
这很好用。问题是它对整个文件使用了 grep
。
我只想在文件的第一行使用 grep
命令。
一开始我尝试过使用head -1 file |
,但是没有成功。
最佳答案
我要添加到您的脚本中的更改是 -
for file in *.csv; do
head -1 "$file" | grep -l -Z -E '.*?FindMyRegex' | xargs -0 -I{} mv {} /home/destination/folder;
done
关于linux - 如何移动第一行包含字符串的文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55024627/