加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

unix – 每行打印一个单词

发布时间:2020-12-16 01:53:39 所属栏目:安全 来源:网络整理
导读:我几乎尝试了所有东西,sed,awk,tr,但…… 我正在尝试输出包含此文件的文件 2079 May 19 13:37 temp.sh 1024 May 23 17:09 mirrad 478 May 26 14:48 unzip.sh 像这样 2079 May 19 13:37 . . . 因此,每个字符串将在变量中一次打印出来. 解决方法 使用xargs的另
我几乎尝试了所有东西,sed,awk,tr,但……

我正在尝试输出包含此文件的文件

2079 May 19 13:37 temp.sh
 1024 May 23 17:09 mirrad
 478 May 26 14:48 unzip.sh

像这样

2079
 May
 19
 13:37
 .
 .
 .

因此,每个字符串将在变量中一次打印出来.

解决方法

使用xargs的另一个简单的衬垫

xargs -n 1 <file

man页面中的-n解释: –

-n max-args,--max-args=max-args
       Use at most max-args arguments per command line.  Fewer than
       max-args arguments will be used if the size (see the -s
       option) is exceeded,unless the -x option is given,in which
       case xargs will exit.

将产生输出

#!/bin/bash
$xargs -n1 <tmp.txt
2079
May
19
13:37
temp.sh
1024
May
23
17:09
mirrad

其中-n值为2

#!/bin/bash     
$xargs -n2 <tmp.txt
2079 May
19 13:37
temp.sh 1024
May 23
17:09 mirrad

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读