我需要从目录/tmp/log
中的文件中提取数据。 我没有问题从单个文件中提取。如何从多个文件中读取数据行
#!/bin/bash
while read line;
do
echo $line
done < /tmp/log/file1
我要与多个文件/tmp/log/*
尝试,但它返回的错误ambiguous redirect
。 任何想法我怎么能围绕它?
我需要从目录/tmp/log
中的文件中提取数据。 我没有问题从单个文件中提取。如何从多个文件中读取数据行
#!/bin/bash
while read line;
do
echo $line
done < /tmp/log/file1
我要与多个文件/tmp/log/*
尝试,但它返回的错误ambiguous redirect
。 任何想法我怎么能围绕它?
你可以读取文件中的for循环如下:
for file in /tmp/log/*; do
while read -r line; do
echo "$line"
done < "$file"
done
该战略只是一个包裹while循环的循环,在一个需要处理每个文件之一的护理时间。
不知道到底你需要啥子.. 也许您正在寻找这样的:
cat /tmp/log/*
这是你需要什么?
for line in `cat /tmp/log/*`
do
echo $line
done
它确实做了工作,但我想按行处理数据行 – conandor 2012-02-28 07:21:17
在这种情况下,您可以使用进程替换:'while read line;做...;完成<<(cat/tmp/log/*)' – 2012-02-28 11:33:40
这正是我所寻找的。谢谢jcollado! – conandor 2012-02-28 07:30:44
这是有趣的循环,其中为循环提供文件while循环。 – kartik 2016-03-17 06:03:03