Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从一行生成列[bash]_Bash_Shell_Awk_Sed - Fatal编程技术网

从一行生成列[bash]

从一行生成列[bash],bash,shell,awk,sed,Bash,Shell,Awk,Sed,有这样一行文字: a b c d e f ... 我想要这个: a b c d e f ... 我正在尝试使用sed,awk,for循环,但我没有得到它 你能帮我吗 谢谢 awk肯定能做到。但是对于给定的示例和预期结果,我将使用xargs: xargs -n2 -a file 测试: 我假设空格之间可能有不止一个字符,所以 $ cat tmp.txt a b c d e f g h i j k l m n o p q r s t u v w x y z $ cat tmp.txt |

有这样一行文字:

a b c d e f ...
我想要这个:

a b
c d
e f
...
我正在尝试使用sed,awk,for循环,但我没有得到它

你能帮我吗


谢谢

awk肯定能做到。但是对于给定的示例和预期结果,我将使用
xargs

xargs -n2 -a file
测试:


我假设空格之间可能有不止一个字符,所以

$ cat tmp.txt 
a b c d e f g h i j k l m n o p q r s t u v w x y z

$ cat tmp.txt | sed 's/\([^ ]* [^ ]*\) /\1\n/g'
a b
c d
e f
g h
i j
k l
m n
o p
q r
s t
u v
w x
y z
使用
rs

$ echo a b c d e f ... | rs -C\  0 2
a b 
c d 
e f 
... 
NAME
     rs — reshape a data array

SYNOPSIS
     rs [-C[x]] [rows [cols]]

DESCRIPTION
     ...
     -C[x]   Output columns are delimited by the single character x.  
             A missing x is taken to be ‘^I’.
man rs

$ echo a b c d e f ... | rs -C\  0 2
a b 
c d 
e f 
... 
NAME
     rs — reshape a data array

SYNOPSIS
     rs [-C[x]] [rows [cols]]

DESCRIPTION
     ...
     -C[x]   Output columns are delimited by the single character x.  
             A missing x is taken to be ‘^I’.

仅使用
bash

$ IFS=$' \t' read -ra a <<< "a b c d e f"
$ printf '%s %s\n' "${a[@]}"
a b
c d
e f
$IFS=$'\t'阅读-ra了解为什么你会获得否决票,你的问题可能最终会被关闭。可能会有帮助