如何从一个给定的文本文件中删除所有的空格 [英] How to remove all white spaces from a given text file

查看:141
本文介绍了如何从一个给定的文本文件中删除所有的空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从一个给定的文本文件中删除所有的空格。是否有任何shell命令可用于此?或者说,如何使用 SED 用于这一目的。

我想要的东西,象下面这样:


  

$猫hello.txt的| SED ....


我试过这样:猫hello.txt的| SED的/ // G'。但它仅删除空格,制表符不


解决方案

  $男人TR
名称
    TR - 翻译或删除字符概要
    TR [选项] ... SET1 [SET2]描述
   转换,压缩和/或删除标准字符
   输入,写标准输出。

您可以试试:

 猫file.txt的| TR -d\\ t \\ n \\ r

I want to remove all the white spaces from a given text file. Is there any shell command available for this ? Or, how to use sed for this purpose.

I want something like below:

$ cat hello.txt | sed ....

I tried this : cat hello.txt | sed 's/ //g' .But it removes only spaces, not tabs.

解决方案

$ man tr
NAME
    tr - translate or delete characters

SYNOPSIS
    tr [OPTION]... SET1 [SET2]

DESCRIPTION
   Translate, squeeze, and/or delete characters from standard 
   input, writing to standard output.

You can try:

cat file.txt | tr -d " \t\n\r" 

这篇关于如何从一个给定的文本文件中删除所有的空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆