#!/bin/bash
filename="./input.txt"
num=0
cat $filename | while read line
do
if [[ `echo $line | grep '帐号'` != "" ]]; then
user=`echo $line | awk '{print $2}'`
num=$(expr $num + 1)
elif [[ `echo $line | grep '密码'` != "" ]]; then
pass=`echo $line | awk '{print $2}'`
num=$(expr $num + 1)
fi
if [[ $num == 2 ]]; then
echo "匹配到: $user, $pass"
echo "$user,$pass" >> ./output.txt
num=0
fi
done
例
----------------------------
afdkjakdsjfkja
adsfkdasjfk
网址 http://www.a.com
帐号 userA
密码 passA
afdkjakdsjfkja
adsfkdasjfk
网址 http://www.b.com
帐号 userB
密码 passB
----------------------------
http://www.test.com
网址 http://www.c.com
帐号 userC
密码 passC
http://www.test.com