[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: 用什么命令能实现这样的处理



Hi, "Vern Sun" <s5unty@gmail.com> :

On Sat, 3 Mar 2007 12:35:03 +0800
"Vern Sun" <s5unty@gmail.com> wrote:

> 准确的说:文件file中的每一行,都将作为参数传递给系统调用date
> 
> 在07-3-3,Vern Sun <s5unty@gmail.com> 写道:
> >
> > 一个文本文件file,文件中的每个参数用来传递给一个系统调用,假设系统调用为date,文件内容为:
> > - 8<  ----
> > "+%Y"
> > "+%m"
> > "+%d"
> > - 8<  ----
> >
> > 问题是如何用一条命令,把文本文件中的每一行,依次传递给date?

cat xxx | xargs date 

但问题是,date 的 format string 是需要连在一起的,也就是 date "+%Y +%m" 类似的,
xargs 出来的结果是不符合要求的。

所以只能把文件处理一下,把换行去掉。

$ cat test
+%Y
+%m
$ cat test | sed '$!N;s/\n//' | xargs date
2007+03

-- 
A. Because it makes the logic of the discussion difficult to follow.
Q. Why shoudn't I top post?
A. No.
Q Should I top post?

A: Because it destroys the flow of the conversation
Q: Why is it bad?
A: No, it's bad.
Q: Should I top post in replies to mailing lists? 



Reply to: