如何在前端添加10个空间| Unix |

发布于 2025-01-24 21:30:46 字数 519 浏览 2 评论 0原文

我有一个文本文件:abc.txt,其中包含下面的数据,

A Apple a day keeps a doctor away 
B I like to play with Ball
C I have cat at my home
D My Dog name is bob

我想在屏幕上显示输出的前端10个空间,然后我的文件数据

预期输出:

      A Apple a day keeps a doctor away 
      B I like to play with Ball
      C I have cat at my home
      D My Dog name is bob

< Strong>我已经尝试过,但不起作用

命令:

cat ABC.txt  | column -t 

I have a text file : ABC.txt which contain below data

A Apple a day keeps a doctor away 
B I like to play with Ball
C I have cat at my home
D My Dog name is bob

I want to display output on my screen with 10 spaces in a frontend and then my file data

Expected output :

      A Apple a day keeps a doctor away 
      B I like to play with Ball
      C I have cat at my home
      D My Dog name is bob

I have tried this but not working

Command :

cat ABC.txt  | column -t 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

べ繥欢鉨o。 2025-01-31 21:30:46
prefix='          '
sed "s/^/$prefix/" ABC.txt 

^匹配行的开头,这将其替换为10个空间。

如果空间数量有所不同,则可以计算前缀变量,而不是硬编码。参见我如何在bash中重复一个角色?

prefix='          '
sed "s/^/$prefix/" ABC.txt 

^ matches the beginning of the line, and this replaces it with 10 spaces.

If the number of spaces can vary, you can calculate the prefix variable instead of hard-coding it. See How can I repeat a character in Bash?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文