删除空白文件的行中的每个开始,使用bash [英] Delete whitespace in each begin of line of file, using bash

查看:121
本文介绍了删除空白文件的行中的每个开始,使用bash的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能在文件的每一行中删除空格,使用bash
例如,FILE1.TXT。之前:

  GG摹
 GG摹
ŤTTT

  GG摹
GG摹
ŤTTT


解决方案

SED -i的/ // G'your_file 将做到这一点,修改文件就地。

要在一个单独的行的开始只删除空格,使用 SED -iS / ^ * //'your_file

在第一八佰伴pression,我们替换全无空间。
在第二个,我们在一开始使用替换 ^ 关键字

How i can delete whitespace in each line of file, using bash For instance, file1.txt. Before:

  gg g
 gg g
t  ttt

after:

gg g
gg g
t  ttt

解决方案

sed -i 's/ //g' your_file will do it, modifying the file inplace.

To delete only the whitespaces at the beginning of one single line, use sed -i 's/^ *//' your_file

In the first expression, we replace all spaces with nothing. In the second one, we replace at the beginning using the ^ keyword

这篇关于删除空白文件的行中的每个开始,使用bash的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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