---
title: "'for' and 'sed' command"
author: "marlgl"
date: "2009-09-10T23:11:41Z"
tags: []
slug: "for-and-sed-command"
draft: false
lastmod: "2009-09-10T23:11:41Z"
id: 466585
url: "https://marlgl.iteye.com/blog/466585"
---

sed -e '/^sshd/!d' hosts.deny | cut -d' ' -f2
-e '/^sshd/!d' 删除非‘sshd’开头的行
-d' '  空格分隔 
-f2 分隔后所得数组的第二个值

> $ cat hosts.deny
> sshd: 117.21.249.75
> sshd: 58.252.146.187
> sshd: 217.111.0.6
> sshd: 92.243.65.138

for i in $(sed -e '/^sshd/!d' hosts.deny | cut -d' ' -f2); do echo $i;done
for i in $(sed -e '/^sshd/!d' hosts.deny | cut -d' ' -f2); do /home/mg/Downloads/hostDeny/pyip.py $i;done