English 中文(简体)
我怎么能够读到一个档案中的档案名称清单?
原标题:How can I read a list of filenames from a file in bash?

I m 试图撰写一个双面文字,处理一个文件清单,其名字在投入档案中每栏一栏储存,就像一个一样。

find . -type f -mtime +15 > /tmp/filelist.txt
for F in $(cat /tmp/filelist.txt) ; do
  ...
done;

我的问题是档案中的名称。 轮胎可能含有空间,因此,上述氮化物将扩大线。

my text file.txt

<编码>my,text and file.txt。 我如何确定这一点?

最佳回答

使用<条码>

while read F  ; do
        echo $F
done </tmp/filelist.txt

或者利用国际助老会改变你名单的空壳:

OLDIFS=$IFS
IFS="
"
for F in $(cat /tmp/filelist.txt) ; do
  echo $F
done
IFS=$OLDIFS

或者(根据@tangens的建议),将贵方的体体转化为单独的文字,然后使用<代码>find。 s 如果直接发现每个档案,可选择操作。

问题回答

如果没有使用替代程序的临时档案,你可以这样做:

while read F
do
  ...
done < <(find . -type f -mtime +15)

改为

cat $FILE | while read line
do
echo $line
done

您可以转而使用管道,而不是铺设管道。

您可直接使用<代码>-exec para amount of find,并直接使用文档名称:

find . -type f -mtime +15 -exec <your command here> {} ;

<代码>{>为文档名称的持有人。

您认为直线直线直线直线,而后再看 lo。

find . -type f -mtime +15 | while read -r line
do
   printf "do something with $line
"
done

我不是一位神职专家,不管怎样(我通常在废墟或大 p中写我的文字,以便相互交错),但我会利用一种礼让,在你处理之前从每一行走空间。

For Bash Regex: http://www.linuxjournal.com/node/1006996

在鲁比拉的类似情况下(处理一件小事,在使用之前清理每一行):

File.foreach(csv_file_name) do |line| 
    clean_line = line.gsub(/( )/,    ) 
    #this finds the space in your file name and escapes it    
    #do more stuff here
end  

我认为,你可以完全和直接地绕过寻找结果,即:

for F in $(find . -type f -mtime +15) ; do
  ...
done;

我没有保证我的辛迪加是正确的,但我很相信这一概念是可行的。

Edit:如果你真的必须处理档案并填写档案名称清单,而且能够像我前面那样简单地把指挥合并起来,那么你就可以改变“IFS的可变性——对内地分配器——的面值,以改变bash如何确定田地。 否则,它就被安排为白色空间,因此,新路线、空间或制片将开始一个新的领域。 如果你只设定一条新线,那么你就能够像你以前那样,把档案放在一起。





相关问题
What does it mean "to write a web service"?

I just asked a question about whether it was possible to write a web-page-checking code and run it from free web server, and one supporter answered and said that it was possible only if I run "a web ...

How can I use exit codes to run shell scripts sequentially?

Since cruise control is full of bugs that have wasted my entire week, I have decided the existing shell scripts I have are simpler and thus better. Here is what I have so far svn update /var/www/...

Dynamically building a command in bash

I am construcing a command in bash dynamically. This works fine: COMMAND="java myclass" ${COMMAND} Now I want to dynamically construct a command that redirectes the output: LOG=">> myfile.log ...

Why does Scala create a ~/tmp directory when I run a script?

When I execute a Scala script from the command line, a directory named "tmp" is created in my home directory. It is always empty, so I simply deleted it without any apparent problem. Of course, when I ...

Ivy, ant and start scripts

I have a project that uses ant to build and ivy for dependencies. I would like to generate the start scripts for my project, with the classpath, based on the dependencies configured in Ivy, ...

热门标签