Hi all,
i have a text file containing details as shown below.i want to extract host and port from the text and paste it in other txt file
必填项:
- 123.256.36.20:1256
- 123.256.36.23:1256
- COLIN1-IMP.COM:1566
- COLIN2-IMP.COM:1586
- 123.256.36.25:1526
使用的代码:
cat for2.txt | perl -ne 'print "$1=$2\n" if(/HOST=([\w.]*.'-'*[\w.]*.).*PORT=(\d+)/)' > in.txt
sed 's|[()]||g' in.txt > in1.txt
通过使用perl我得到了主机和端口值...使用sed我删除了'()'..
获得的输出:
- 123.256.36.20 = 1256
- 123.256.36.23 = 1256
- COLIN1-IMP.COM = 1586
- 123.256.36.25 = 1526
perl未获得与 COLIN1-IMP.COM
相同的 COLIN2-IMP.COM帮帮我..谢谢你
答案 0 :(得分:0)
我找到了我怀疑的答案,我想与大家分享。
cat sample1.txt | perl -nle 's{HOST=([^)]*).*?PORT=([^)]*)}{print "$1:$2"}ge' > sample2.txt