[英]Using Grep or AWK command
I have file with this text information: 我有以下文本信息文件:
http://=
en.domain.com/registration.html#/?doitoken=1D7f1ad404-f84b-4a3b-8931=
-4f40b619730e
http://=
en.domain.com/registration.html#/?doitoken=5D8172f6e6-240f-42e6-8512=
-6d7f6bd61c2d
http://=
en.domain.com/registration.html#/?doitoken=8D8172f6e6-240f-42e6-8512=
-6d7f6bd61c2d
How i can do this using grep or awk command in linux bash: 我如何在Linux bash中使用grep或awk命令做到这一点:
http://en.domain.com/registration.html#/?doitoken=1D7f1ad404-f84b-4a3b-8931-4f40b619730e
http://en.domain.com/registration.html#/?doitoken=5D8172f6e6-240f-42e6-8512-6d7f6bd61c2d
http://en.domain.com/registration.html#/?doitoken=8D8172f6e6-240f-42e6-8512-6d7f6bd61c2d
Thanks for your answers! 感谢您的回答!
awk 'BEGIN{FS="=\n"; RS=""; OFS=""} {print $1, $2, $3}' input_file
您还可以摆脱OFS=""
并删除print语句中的,
s
Save the program as pr.awk , and run awk -f pr.awk input.dat
将程序另存为pr.awk ,然后运行awk -f pr.awk input.dat
NF {
n++
sub(/=$/, "")
ans = ans $0
}
n==3 { # flush
print ans
ans = ""; n = 0
}
$ awk '/=$/{sub(/=$/,""); printf "%s",$0;next} /./{print}' file
http://en.domain.com/registration.html#/?doitoken=1D7f1ad404-f84b-4a3b-8931-4f40b619730e
http://en.domain.com/registration.html#/?doitoken=5D8172f6e6-240f-42e6-8512-6d7f6bd61c2d
http://en.domain.com/registration.html#/?doitoken=8D8172f6e6-240f-42e6-8512-6d7f6bd61c2d
How it works: 这个怎么运作:
/=$/{sub(/=$/,""); printf "%s",$0;next}
If the line ends with =
, then remove the trailing =
, print the result (without a trailing newline) and jump to the next
line. 如果该行以=
结尾,则删除尾随=
,打印结果(不包含尾随换行符)并跳至next
行。
/./{print}
If we get here, then this line does not end with =
and we just print it normally (with the trailing newline). 如果到达此处,则此行不以=
结尾,而我们只是正常打印(带有尾随换行符)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.