在bash中的Python zip()行为?

前端之家收集整理的这篇文章主要介绍了在bash中的Python zip()行为?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在bash中是否有类似的 Python zip()功能?具体来说,我正在寻找bash中的等效功能,而不使用python:
$echo "A" > test_a
$echo "B" >> test_a
$echo "1" > test_b
$echo "2" >> test_b
$python -c "print '\n'.join([' '.join([a.strip(),b.strip()]) for a,b in zip(open('test_a'),open('test_b'))])"
A 1
B 2
纯粹的bash:
liori@marvin:~$zip34() { while read word3 <&3; do read word4 <&4 ; echo $word3 $word4 ; done }
liori@marvin:~$zip34 3<a 4<b
alpha one
beta two
gamma three
delta four
epsilon five
liori@marvin:~$

(老回答)看看加入.

liori:~% cat a
alpha
beta
gamma
delta
epsilon
liori:~% cat b
one
two
three
four
five
liori:~% join =(cat -n a) =(cat -n b)
1 alpha one
2 beta two
3 gamma three
4 delta four
5 epsilon five

(假设你有=() operator like in zsh,否则会更复杂).

猜你在找的Bash相关文章