将返回字符替换为

时间:2014-01-27 09:46:45

标签: xml bash sed fedora pki

我在一个文件中有pkcs10请求,我需要将文件中的新行字符转换为“ “

示例:

-----BEGIN NEW CERTIFICATE REQUEST-----
MIIC2zCCAcMCAQAwcjELMAkGA1UEBhMCVVMxEDAOBgNVBAoTB1JlZCBIYXQxDjAM
BgNVBAsTBVFFSURNMQswCQYDVQQLEwJRRTENMAsGA1UECxMEUkhTUzEVMBMGCgmS
JomT8ixkAQETBXRlc3Q2MQ4wDAYDVQQDEwV0ZXN0NjCCASIwDQYJKoZIhvcNAQEB
BQADggEPADCCAQoCggEBALQULllI/JMudcBHeykXe7wRmAZlcxxQK7pvw1hNqt/I
Lz4XdZJ9pZVHCSmeR3ubsriRbbqhM2ZjiH+Rb2mLxCgrVlqvBEZ5qj6yQhhiWaFL
wNIGFhGHqFt/HeDxDvuLumZVH34VDGZoIoPLVMtVspHG5kxKHEsivWMvkkUnrbJF
X8Bdsfhzg/7pObkZtaUrg9tjXRCU+hrPnodfUgZ8IxzWcaaKFs7c4f6QjFOsDCQz
8TxuiF5gDbWbXlpVRnEtofpMZrtnxYe92Sepi83kduZ9aWyZMFNND8HWl9zpjwy3
uFUrs+R+S8zRM3tww92CuCgsaA+fjftlFKnIXaAl7dkCAwEAAaAkMCIGCCsGAQUF
BwcXMRYEFOZpyV8u/6SQrnPmRMw/nh2Wd5xQMA0GCSqGSIb3DQEBBAUAA4IBAQCm
djxD+5NJqFIKKWaVEq3QNDwqNiD/j+bi7EyDPquwBfgpp1VZmOty99muStG2GfvE
1tg7ZdcebDHZ5umIw//3StxTODVkUYIkYzWERdt3GZe3TJqdGDeWMkOtCQR0fMjs
X1TN0m1BEKS1tKoMJWJagCLvsqr2C+LMw4gB/r/Tq+KUvacM+yv7x0ROgRKa6aiW
/ja2vox3uWUMUMKYbz8km5UrqnaSBVDvDIt8yt9X5k+2sgl37MsWzyKBnpwH7mKX
5Z8vj9C8F3Iq0L6qWQdqCY74nm/jyI4roUQpDoS+xeQxKh6mn8IbX2HisGwSoJyM
w8jfHjDvXxRi0RyBlBNR

-----结束新证书请求-----

我想将上述格式更改为以下格式:

-----BEGIN NEW CERTIFICATE REQUEST-----
MIIC2zCCAcMCAQAwcjELMAkGA1UEBhMCVVMxEDAOBgNVBAoTB1JlZCBIYXQxDjAM
BgNVBAsTBVFFSURNMQswCQYDVQQLEwJRRTENMAsGA1UECxMEUkhTUzEVMBMGCgmS
JomT8ixkAQETBXRlc3Q2MQ4wDAYDVQQDEwV0ZXN0NjCCASIwDQYJKoZIhvcNAQEB
BQADggEPADCCAQoCggEBALu2ootYtjVwwmTSDh2mQxbgWGOgMLEHlvzbG6Xzdqc0
c8mQkm8jZvB4JE5TiXmNj4YWnnJNehKCqog3xUwpNo6P1uW5l0p1D2Dk9n/pCuvW
zQ237mWBB6tYoHYiqyFgcip7ptbytQjykhx+1UbqgnACVW2FHaVLcGSyfMRoaOZS
LjxZUui4aFDe9pS9nv0Dk+34/xJS2y/UjKTFMziieQzmBT63Yk+1NMmlGIrVl+en
hvh6bctMdpeaTkDy327+y/BeQzR3qoUK4RcOB6vq1u40PkKwwy/lGF2mCNwIQnBY
ExZsr6nuC1kMgRG7776scMztO4rtoUtkazjxIJc5K3MCAwEAAaAkMCIGCCsGAQUF
BwcXMRYEFOZpyV8u/6SQrnPmRMw/nh2Wd5xQMA0GCSqGSIb3DQEBBAUAA4IBAQA7
L0p4N4/94u4d4RgYoPuBVH09J12CXh/NtKUsiiTRC41IaVggSoe3L3bR20DhELtZ
IIbtrijktg9eNkUHfIQmZu9GjIs9GtKQMQx7YbOC9xHq7kWffxbUyTgQ6pFQyoGE
toGME2wP6MPhEkUNiIYNam8Tt+qUiz6t5j3MGB8HwoF+qNpEfo8tNtfgonpOnYns
i2SUbc1Y1Nj15IZfkMXRdaRj+a0HxLR7kDVayRYxO5H4cHuCG9N0vLkNtkdwPboI
TyoNsrSqgZVP2U7B82qfo8YcSTG2D/B8KHnSbMIYCl1e3u//b6zcC1NODpffOYCF
xVxiFitfbtweWcWipxWS

-----END NEW CERTIFICATE REQUEST----

Linux上可以实现上述功能的任何工具,如xed或xml工具。

2 个答案:

答案 0 :(得分:1)

您可以使用sed

sed ':a;N;$!ba;s/\n/\
&/g' filename

要将更改保存到输入文件,请添加-i选项。

对于您的输入,这将产生:

-----BEGIN NEW CERTIFICATE REQUEST-----
MIIC2zCCAcMCAQAwcjELMAkGA1UEBhMCVVMxEDAOBgNVBAoTB1JlZCBIYXQxDjAM
BgNVBAsTBVFFSURNMQswCQYDVQQLEwJRRTENMAsGA1UECxMEUkhTUzEVMBMGCgmS
JomT8ixkAQETBXRlc3Q2MQ4wDAYDVQQDEwV0ZXN0NjCCASIwDQYJKoZIhvcNAQEB
BQADggEPADCCAQoCggEBALQULllI/JMudcBHeykXe7wRmAZlcxxQK7pvw1hNqt/I
Lz4XdZJ9pZVHCSmeR3ubsriRbbqhM2ZjiH+Rb2mLxCgrVlqvBEZ5qj6yQhhiWaFL
wNIGFhGHqFt/HeDxDvuLumZVH34VDGZoIoPLVMtVspHG5kxKHEsivWMvkkUnrbJF
X8Bdsfhzg/7pObkZtaUrg9tjXRCU+hrPnodfUgZ8IxzWcaaKFs7c4f6QjFOsDCQz
8TxuiF5gDbWbXlpVRnEtofpMZrtnxYe92Sepi83kduZ9aWyZMFNND8HWl9zpjwy3
uFUrs+R+S8zRM3tww92CuCgsaA+fjftlFKnIXaAl7dkCAwEAAaAkMCIGCCsGAQUF
BwcXMRYEFOZpyV8u/6SQrnPmRMw/nh2Wd5xQMA0GCSqGSIb3DQEBBAUAA4IBAQCm
djxD+5NJqFIKKWaVEq3QNDwqNiD/j+bi7EyDPquwBfgpp1VZmOty99muStG2GfvE
1tg7ZdcebDHZ5umIw//3StxTODVkUYIkYzWERdt3GZe3TJqdGDeWMkOtCQR0fMjs
X1TN0m1BEKS1tKoMJWJagCLvsqr2C+LMw4gB/r/Tq+KUvacM+yv7x0ROgRKa6aiW
/ja2vox3uWUMUMKYbz8km5UrqnaSBVDvDIt8yt9X5k+2sgl37MsWzyKBnpwH7mKX
5Z8vj9C8F3Iq0L6qWQdqCY74nm/jyI4roUQpDoS+xeQxKh6mn8IbX2HisGwSoJyM
w8jfHjDvXxRi0RyBlBNR

-----END NEW CERTIFICATE REQUEST-----

答案 1 :(得分:1)

sed '$ !s/$/\
/' YourFile

sed '$ !s/[[:blank:]]*$/\
/' YourFile

还不够?