【发布时间】:2013-03-16 10:16:09
【问题描述】:
我正在寻找一种绕过文件读写的方法。
是否可以直接在命令结果上使用 sed?
#!/bin/sh 被使用,因为我使用 NetBSD,sed -i 不起作用,所以我必须使用 sed -e 然后将结果重定向到文件。
命令结果disklabel xbd0
netbsd# disklabel xbd0 >/file ;
# /dev/rxbd0d:
type: unknown
disk: xbd0
label:
flags:
bytes/sector: 512
sectors/track: 2048
tracks/cylinder: 1
sectors/cylinder: 2048
cylinders: 1000
total sectors: 2048000
rpm: 3600
interleave: 1
trackskew: 0
cylinderskew: 0
headswitch: 0 # microseconds
track-to-track seek: 0 # microseconds
drivedata: 0
16 partitions:
# size offset fstype [fsize bsize cpg/sgs]
a: 2048000 0 4.2BSD 1024 8192 0 # (Cyl. 0 - 999)
c: 2048000 0 unused 0 0 # (Cyl. 0 - 999)
d: 2048000 0 unused 0 0 # (Cyl. 0 - 999)
netbsd# disklabel xbd0 | sed -e "s/match1/replace/" \
-e "s/match2/replace/" \
-e "s/match3/replace/" /file > /file.1 ;
如何在另一个命令中发送结果?
$ new_command -add $(results)
【问题讨论】:
-
您是否尝试重定向命令“disklabel xbd0 | sed -e "s/match1/replace/" \ -e "s/match2/replace/" \ -e "s/match3/ 的结果将/“/file”替换为/file.1?
标签: shell redirect sed command sh