Linux命令之乐--awk

1.脚本参数传值

#/bin/bash
awk 'BEGIN {a="'$'"} {if(($1==a)) print $2;}' /etc/hosts

执行结果:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAbcAAAAtCAIAAACif7ItAAAFDUlEQVR4nO2d24HjIAxF3ZPboRj3Qi2UMn3Mh2NbPCTArzjJOV+zYwwCiYuAzGYYVJz/W/FOL/e7OP81AyOcHabx3dYAwOcjlxCUBQAAAAAAAAAAAAAA4IW4RMlumz/9jn6xv832cQqf2c2b6BvNfsYpcI8HtzNOwY5p57eglD/31vNkmj9shEo2cPVHt5xHJeFWauqWPFYj9DdU8gamMI+w85+qx6gknMy7d6y2umVPUcmD7dQ++7mI47io5cXWXNDGJ6nkFIx5t7lLj/kTpq5pQ9RQwYyT/lChboPFaoQV1UdGynntzbVm7wxDog9eh8k0MCmQfGa7VL/z6ytrSHSo5OudME1eNpAYEMJWc9yIPOY6uJzEw+B9kEPxmtcuslId5t5uFm0xDi5uSiW1yNO6WpKEYvSvKhnN4G7TNGcNzv8F78PfzsqzVpTXp/B6NLs3c9gm1vPI7J/+ZhdGo/ZxtnGMfzzfhurry7permQbv70Ls66SwzC8xMf7rXk5e5yPzcrqqhao5YBLwK/nceMUOnPJ2Qfbo+Rkb41FWXDWiq2CEORLY/fCl0rO1mhvE3u7mZXNR7Fh0ToRZVbFI1MYt7xPWUhsueSuY9yas5aBWsscOCtOJ0j2ZByG8vwfp5AsFns9pdtQrVk60Vh6D9rQTOapYRiSuZROkx77bJU0FpLilfPyy2oBtZAs7d0gpsculYzfGCeZGojXxE5N5LBF90cyWqeWmLU3sbeb1eaSRjs72E0l7EQxaejmfdGFbERkZr4z66/dJzYPdUNbdZWsiUj/st1mg8zflRVzWTH8sa3HGSqp+DvJhct5+c66ZRvK0/IToS/VApUGhk241sh9j0oW/Nd7OBVnakmF7U3cpZLXbriN7VmW0aYnMOL8Z9lE5acT8/bn+DlXyVn3qKSc3PpeslLJKTbInZZ1pHYkXI6qpDzBTR4l5xVfqpKitoVS+aerZPpy1IsHqOQYpw1G+nAcLebyDXLaq1f3nf/zbh60QjfnKRfOun0qnSNdr5KZR7TOHLv3MG2Ic9RiQ4vHxLJ1rg09FE9Q35xL3rTjboyAB++4i6ZFOfFTdtzrcB9LJe239UQy71u+UEwhTNPsHfe6RUmbyg6ze4ysO+sulRSta1O0QZvqnmzLJYtmROKh71CO2NBaw2ZwWu6mc0kz0P5ixbFvb0r+TgYgsad5ul6bS0aJSe8xUH5HmXqz3EQp5C5VyfWC+8jHgNbNj9K6EXClUChsp9dfKiIh/Ki1phtZd9bpKlm9FlCdlUyV0kiYvqjasA1GMSLlTNDWpMM2VGoQB7haaF14x13egRVzQ/1pS4Fka1FKmNd+paKZnWKt4zmmj8UJz/JveZoxRpNuOZR+5VXexUb2rUXb5wSEfWkPzCa0br5KVbpZdEkpVE5KJa3Xa2GahEJ+5hXFQ9aRtLwcUnt1lvWrzorqiz8sti8sjFcrx32FkFBFpKrCVkt2KEk7VLcetsGqIXaJ0oawcldcV3LJJ5CH5q24B/1hzDnoeyMAyPkAlXwzqCTAb7N/x/ArfJFKtmyPAADaSQ5/UBYAAAAAAAAAAAAAALgSbrcBAFqw/5IaAODXQSUBACxQSQAAi6d/YwwAwHt59DfGAAC8nQf//7UAAA/go74LAQDgdlBJAAALdtwAABYP/sYYAIC38RHfGAMA8NV80f/yDQBwAagkAIAFKgkAoMA3xgAAAAAAAAAAAPw6/4v/X68OL/huAAAAAElFTkSuQmCC" alt="" />

2.awk的多分割条件

分别以空格,/和问号都将作为分隔符

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAnIAAABSCAIAAABff67dAAAOOUlEQVR4nO2d2bXsKAxFK6dKx8E4F2JxKDeO7g9PAiQkT2VXvb1Xf/S7xiAmHTMUvF4AAAAAAAAAcJgu/c2kzn5WP/wCZvtjtr/74TuzeRNT6Q79+25LAAA+xLsf2jrRpdUtyv/fGs+T6RKyOnFBPfbD82T1eDa/usEDwIV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AGiw5ZzGJ95ZDwAA8CCQVQAAgNNAVgEA4IfRTpwW66DW4cv15dsivLiZQD1punXuskwYWQUAgO9DFbp3dQuolFL1vMr1epYppHY9gSWr/nVFAAAA38CqoOIkbql+wWtpQ5ePGrLqXq4LAADwJcznXOe3562S1lBC+YcDlwwrqvpiEhgAAL6SSeq6NN43PfTjAHZ5jqwCAABsoB+Gvh9lskt/Q0qZ9m2YBN4pq0wCAwDADyGmf7P/z57n49f4bqRQILYsAQDAz5CJmjFMzH5gkyvj+iudPz1Mcaeicbli/QOb6FmHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADP4D/vPwAAAIiCrALAv8r/FWyz8ae/IHsAAAAASUVORK5CYII=" alt="" />

3. 先匹配到某行,然后分割

Linux命令之乐--awk

上一篇:C# WinForm 技巧:控件截图


下一篇:Maven学习