• Home
  • Archives
  St0p's Blog
  • Home
  • Archives
  • Mac
  • Go
  • Php
  • Docker
  • Nginx
  • CentOs
  • Shell
  • Linux

批量提取不规则文件中帐号密码不在同一行的数据进行合并

#!/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
2018/8/23 21:53 下午 posted in  Shell

St0p's Blog

接触越多发现自己不懂的越多,只能慢慢前行,努力超越现在的自己!
RSS

Categories

Mac Go Php Docker Nginx CentOs Shell Linux

Recent Posts

  • Centos 7 安装XFCE桌面
  • centos 安装xrdp远程连接桌面
  • MAC下BREW安装PHP 5.6
  • Vim 十六进制模式修改文件
  • MAC OSX VPN自动添加静态路由

Copyright © 2015 Powered by MWeb,  Theme used GitHub CSS.