txtファイルの
n*1行のfield2を出力
n*2行のfield3を出力
n*3行のfield5を出力
n=0,1...n
結果は別のファイルに保存するが、
方法を教えていただけませんか?
thanks
Leeさんの<3F0A9DA9...@partner1.nri.co.jp>から
>txtファイルの
>n*1行のfield2を出力
>n*2行のfield3を出力
>n*3行のfield5を出力
>n=0,1...n
>結果は別のファイルに保存するが、
>方法を教えていただけませんか?
やりたいことが今ひとつわかりませんです。
[sample.txt]
a01 b01 c01 d01 e01
a02 b02 c02 d02 e02
a03 b03 c03 d03 e03
a04 b04 c04 d04 e04
a05 b05 c05 d05 e05
a06 b06 c06 d06 e06
上記のようなテキストファイルがあったときに以下のような
3つのファイルを出力したいということですか?
[ファイル1]
b01
b02
b03
b04
b05
b06
[ファイル2]
c02
c04
c06
[ファイル3]
e03
e06
--
Tanaka-Qtaro-Yasuhiro mailto:ta...@ca2.so-net.ne.jp
fj.unix.shellsの記事<3F0A9DA9...@partner1.nri.co.jp>で
gnt0...@partner1.nri.co.jpさんは書きました。
> n=0,1...n
nは1から開始、ですよね?
--
太田純(Junn Ohta) (株)リコー/新横浜事業所
oh...@sdg.mdd.ricoh.co.jp
たとえばフィールド区切りが':'のとき、cshならこんな
具合ですかね。結果は標準出力に書き出されます。
sample
--------------------------------------------------
#! /bin/csh -f
# Usage: sample filename n
set file = $1
@ n = $2
@ i = 1
while ($i <= $n)
@ i1 = $i * 1
@ i2 = $i * 2
@ i3 = $i * 3
head -$i1 $file | tail -1 | cut -d ':' -f 2
head -$i2 $file | tail -1 | cut -d ':' -f 3
head -$i3 $file | tail -1 | cut -d ':' -f 5
@ i++
end
--------------------------------------------------
infile
--------------------------------------------------
01-1:01-2:01-3:01-4:01-5:01-6:01-7:01-8:01-9
02-1:02-2:02-3:02-4:02-5:02-6:02-7:02-8:02-9
03-1:03-2:03-3:03-4:03-5:03-6:03-7:03-8:03-9
04-1:04-2:04-3:04-4:04-5:04-6:04-7:04-8:04-9
05-1:05-2:05-3:05-4:05-5:05-6:05-7:05-8:05-9
06-1:06-2:06-3:06-4:06-5:06-6:06-7:06-8:06-9
07-1:07-2:07-3:07-4:07-5:07-6:07-7:07-8:07-9
08-1:08-2:08-3:08-4:08-5:08-6:08-7:08-8:08-9
09-1:09-2:09-3:09-4:09-5:09-6:09-7:09-8:09-9
10-1:10-2:10-3:10-4:10-5:10-6:10-7:10-8:10-9
--------------------------------------------------
に対して
./sample infile 3 > outfile
を実行すると、
outfile:
--------------------------------------------------
01-2
02-3
03-5
02-2
04-3
06-5
03-2
06-3
09-5
--------------------------------------------------
となります。