apache - 如何从Powershell输出中删除多余的空格?

标签 apache powershell ssh

我正在使用Powershell ssh进入我的Linux服务器并尾随我的apache日志文件。

ssh user@domain.tld -p800 -i ..ssh \ id_rsa_test tail / var / log / httpd / access_log -fn0> test.log

尾部文字看起来不错,打开文件时,我通过管道将其插入其中看起来不错。

我正在管道输出的应用程序失败。当我拖尾文件时,我看到的是每个单个字符都用空格分隔。

使用不带参数的输出文件会做同样的事情。当我将记事本中的文件内容剪切并粘贴到另一个记事本文件时,另一个应用程序可以读取它。我怎样才能解决这个问题?

这是我所指的示例:

d o m a i n . c o m 7 2 . 2 2 4 . 2 4 9 . 1 7 - - [ 1 0 / D e c / 2 0 1 3 : 0 7 : 5 0 : 5 6 - 0 6 0 0 ] " G E T / v a n e / v i e w f o r u m . p h p ? f = 1 & s i d = 3 b 4 3 b d 9 9 9 a 7 d b 2 0 c 6 6 9 7 5 b 2 3 8 2 4 a 9 6 1 9 H T T P / 1 . 1 " 2 0 0 9 3 7 6 " h t t p : / / w w w . d o m a i n . c o m / j a n e / v i e w t o p i c . p h p ? f = 1 & t = 8 0 2 3 & p = 3 4 3 4 5 0 & s i d = 3 b 4 3 b d 9 9 9 a 7 d b 2 0 c 6 6 9 7 5 b 2 3 8 2 4 a 9 6 1 9 " " M o z i l l a / 4 . 0 ( c o m p a t i b l e ; M S I E 8 . 0 ;
W i n d o w s N T 6 . 0 ; W O W 6 4 ; T r i d e n t / 4 . 0 ; G T B 7 . 5 ; S L C C 1 ; . N E T C L R 2 . 0 . 5 0 7 2 7 ;
M e d i a C e n t e r P C 5 . 0 ; . N E T C L R 3 . 5 . 2 1 0 2 2 ; . N E T C L R 3 . 5 . 3 0 7 2 9 ; M D D C ; . N E T C L R 3 . 0 . 3 0 7 2 9 ; . N E T 4 . 0 C ; B R I / 1 ; B R I / 2 ) " d o m a i n . c o m 5 . 9 . 1 0 6 . 2 4 1 - - [ 1 0 / D e c / 2 0 1 3 : 0 7 : 5 0 : 5 8 - 0 6 0 0 ] " G E T / r o b o t s . t x t H T T P / 1 . 0 " 2 0 0 - " - " " M o z i l l a / 5 . 0 ( c o m p a t i b l e ; M J 1 2 b o t / v 1 . 4 . 4 ; h t t p : / / w w w . m a j e s t i c 1 2 . c o . u k / b o t . p h p ? + ) "

最佳答案

如果通过输出文件,设置内容或添加内容通过管道传输输出,则可以使用-Encoding参数将其强制为ASCII:

ssh user@domain.tld -p800 -i ..ssh\id_rsa_test tail /var/log/httpd/access_log -fn0 | Add-Content  test.log -encoding ASCII

ssh user@domain.tld -p800 -i ..ssh\id_rsa_test tail /var/log/httpd/access_log -fn0 | Set-Content  test.log -encoding ASCII

ssh user@domain.tld -p800 -i ..ssh\id_rsa_test tail /var/log/httpd/access_log -fn0 | Out-File  test.log -encoding ASCII

关于apache - 如何从Powershell输出中删除多余的空格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20496419/

相关文章:

php - 如何找出导致我的 PHP 应用程序挂起 Apache 服务器的原因?

java - InvalidInputException:输入路径不存在

windows - 如何从 Windows 资源管理器启动 PowerShell?

Powershell 通过指纹作为字符串与字符串变量检索证书

git - EC2/AWS、 Jenkins 、Git、SSH

linux - Docker 容器中运行多个 httpd 进程

mysql - Centos7 上无法从 PhpMyadmin 连接到 Mysql

mysql - 写入 my.cnf 时出错 : Permission denied

class - Powershell 类实现 get set 属性

python - Openshift:如何从私有(private)存储库安装 python 模块?