我有一些文本输出,如下所示:
+-------------------------+-----+--------------------------------+--------------------------------------------+
| Site | SSL | URL | Path |
+-------------------------+-----+--------------------------------+--------------------------------------------+
| samplerds.test | | http://samplerds.test | /Users/user01/Paths/samplexx1 |
| wpo.test | | http://wpo.test | /Users/user01/Paths/wpo |
+-------------------------+-----+--------------------------------+--------------------------------------------+
有什么方法可以使用解析上面的文本awk
或sed
将它们转换为以下内容:
samplerds
wpo
干杯
答案1
使用awk
:
$ awk -F '[ .]' 'NR>3 && !/^\+/ {print $2}' file
samplerds
wpo
或添加子域作为字段分隔符:
awk -F ' |\.test' 'NR>3 && !/^\+/ {print $2}' file
或者gsub
当你有子域时它也可以工作:
awk 'NR>3 && !/^\+/ {gsub("\.[^.]*$","",$2); print $2}' file