将文本文件合并为一行,删除制表符和双逗号(DKIM 密钥)

将文本文件合并为一行,删除制表符和双逗号(DKIM 密钥)

我可以使用以下命令将所有行合并为一行

cat input.txt | tr -d '\n' > output.txt

但正如您在下面看到的,我的数据是用制表符和双逗号分隔的。

mail._domainkey IN  TXT ( "v=DKIM1; k=rsa; t=s; s=email; "
    "p=MBIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AEIIBCgKCAQEAxZfSF9WkStkz1A0tbSNWAEdyHiWfenEeihvzVn8mCOx7nsUBYnEDocbDb8P0pTHS8MVNZ4jhXSwkg5mc6+NVgyZIctSogUMdD1ddGsYDfUHgT/d5tsVTzecgRtTtpdxibRyh1HY5Zmg2wxFLuCPqMPVeJHjwfKwwQHHCQtIVH+b+QvmF6hxODu73UwNUaG1cr8UkLqoQexTGoS"
    "qqmGCYGKk5ImzSIoa40L1gpcSPtIWbsVTSXK1FLsovGHd7NMmEHBgv2WabpDL4BQeEfSZC0Rk5sZEaWrepiHBiTcNjhb5tyLkgxmUIW21sOA+2kmChQUwyp10qDaP5h/+s7R0arQIDAQAB" )  ; ----- DKIM key mail for domain.comtest

我怎样才能得到以下输出?

mail._domainkey IN  TXT ( "v=DKIM1; k=rsa; t=s; s=email; p=MBIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AEIIBCgKCAQEAxZfSF9WkStkz1A0tbSNWAEdyHiWfenEeihvzVn8mCOx7nsUBYnEDocbDb8P0pTHS8MVNZ4jhXSwkg5mc6+NVgyZIctSogUMdD1ddGsYDfUHgT/d5tsVTzecgRtTtpdxibRyh1HY5Zmg2wxFLuCPqMPVeJHjwfKwwQHHCQtIVH+b+QvmF6hxODu73UwNUaG1cr8UkLqoQexTGoSqqmGCYGKk5ImzSIoa40L1gpcSPtIWbsVTSXK1FLsovGHd7NMmEHBgv2WabpDL4BQeEfSZC0Rk5sZEaWrepiHBiTcNjhb5tyLkgxmUIW21sOA+2kmChQUwyp10qDaP5h/+s7R0arQIDAQAB" )  ; ----- DKIM key mail for domain.com

答案1

cat input.txt | tr -d '\n\r\t\"' > output.txt
这应该可以正常工作。

答案2

我认为它们不是制表符而是空格。 Perl 的工作原理:

cat input.txt | perl -00 -pe 's/"\n\s+"//g' > output.txt

答案3

使用GNUsed

$ sed -z 's/"\n[^"]*"//g' input_file > output.txt
$ cat output.txt
mail._domainkey IN  TXT ( "v=DKIM1; k=rsa; t=s; s=email; p=MBIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AEIIBCgKCAQEAxZfSF9WkStkz1A0tbSNWAEdyHiWfenEeihvzVn8mCOx7nsUBYnEDocbDb8P0pTHS8MVNZ4jhXSwkg5mc6+NVgyZIctSogUMdD1ddGsYDfUHgT/d5tsVTzecgRtTtpdxibRyh1HY5Zmg2wxFLuCPqMPVeJHjwfKwwQHHCQtIVH+b+QvmF6hxODu73UwNUaG1cr8UkLqoQexTGoSqqmGCYGKk5ImzSIoa40L1gpcSPtIWbsVTSXK1FLsovGHd7NMmEHBgv2WabpDL4BQeEfSZC0Rk5sZEaWrepiHBiTcNjhb5tyLkgxmUIW21sOA+2kmChQUwyp10qDaP5h/+s7R0arQIDAQAB" )  ; ----- DKIM key mail for domain.com

相关内容