如何使用linux中的for
循环获取文件的第二列?
ATTACHMENT vol-f66 i-26048111 /dev/sda1 attached 2013-11-20T06:42:49+0000 true
ATTACHMENT vol-3db i-e1c443d6 /dev/sda1 attached 2013-11-21T12:38:09+0000 true
我想实现类似的东西 -
for /f "tokens=2" %%s in (%EC2_HOME%\Volumes.txt) do call ec2-create-snapshot %%s
答案 0 :(得分:0)
将其反馈给awk '{print $2}'
。您可以立即编辑\n
的分隔符,也可以取消for
循环。
实施例 -
echo "ATTACHMENT vol-f66 i-26048111 /dev/sda1 attached 2013-11-20T06:42:49+0000 true
ATTACHMENT vol-3db i-e1c443d6 /dev/sda1 attached 2013-11-21T12:38:09+0000 true
ATTACHMENT vol-sdb i-e1c443d6 /dev/sda1 attached 2013-11-21T12:38:09+0000 true
ATTACHMENT vol-3ss i-e1c443d6 /dev/sda1 attached 2013-11-21T12:38:09+0000 true" | awk '{print $2}'
返回 -
vol-f66
vol-3db
vol-sdb
vol-3ss