avatar
[转载] 问个shell怎么写?# Unix - 噫吁兮,危乎高哉
s*e
1
【 以下文字转载自 Programming 讨论区 】
【 原文由 shuke 所发表 】
呵呵,很简单的。我有可执行程序a,执行格式为
a f.input f.output
我一个目录下有10000个input文件,怎么写一个shell
执行a,把这些文件全部转化为output文件
谢谢。
avatar
s*s
2
files=`ls *.input`
for ifn in $files
do
ofn=`echo $ifn|sed -e 's/\.input/\.output'`
a $ifn $ofn
done

【在 s***e 的大作中提到】
: 【 以下文字转载自 Programming 讨论区 】
: 【 原文由 shuke 所发表 】
: 呵呵,很简单的。我有可执行程序a,执行格式为
: a f.input f.output
: 我一个目录下有10000个input文件,怎么写一个shell
: 执行a,把这些文件全部转化为output文件
: 谢谢。

avatar
c*o
3
How about this one?
#!/bin/sh
for i in `ls *.input`
do
head=`echo $i | awk -F"." '{print $1}'`
a $head.input $head.output
done
hehe, did not test it. Use it at your own risk.

【在 s***e 的大作中提到】
: 【 以下文字转载自 Programming 讨论区 】
: 【 原文由 shuke 所发表 】
: 呵呵,很简单的。我有可执行程序a,执行格式为
: a f.input f.output
: 我一个目录下有10000个input文件,怎么写一个shell
: 执行a,把这些文件全部转化为output文件
: 谢谢。

avatar
c*o
4

I would add /g there. That is:
ofn=`echo $ifn|sed -e 's/\.input/\.output/g'`

【在 s**s 的大作中提到】
: files=`ls *.input`
: for ifn in $files
: do
: ofn=`echo $ifn|sed -e 's/\.input/\.output'`
: a $ifn $ofn
: done

avatar
p*a
5
又到了我的强项,哈哈
ls -1 *.input | awk '{print ("a ")($1)(" ")($1)}' | sed 's/input$/output/g' |
sh

【在 s***e 的大作中提到】
: 【 以下文字转载自 Programming 讨论区 】
: 【 原文由 shuke 所发表 】
: 呵呵,很简单的。我有可执行程序a,执行格式为
: a f.input f.output
: 我一个目录下有10000个input文件,怎么写一个shell
: 执行a,把这些文件全部转化为output文件
: 谢谢。

avatar
c*t
6
Makefile is a good tool as well:
INPUT=$(wildcard *.input)
OUTPUT=$(INPUT:.input=.output)
%.output: %.input
@a $< [email protected]
all: $(OUTPUT)

【在 s***e 的大作中提到】
: 【 以下文字转载自 Programming 讨论区 】
: 【 原文由 shuke 所发表 】
: 呵呵,很简单的。我有可执行程序a,执行格式为
: a f.input f.output
: 我一个目录下有10000个input文件,怎么写一个shell
: 执行a,把这些文件全部转化为output文件
: 谢谢。

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。