[英]Summarizing multiple files in unix
I am trying to summarize multiple files parallely. 我试图总结多个文件并行。 As I display variable it contains null 当我显示变量时,它包含null
a=`cat file1| sort | uniq | wc -l` & # file1 have 200k records
b=`cat file2|sort | uniq | wc -l` & # file1 have 240k records
sh -x process1.sh &
wait
echo a=$a
echo b=$b
Output 产量
a=
b=
Expected Output 预期产量
a=200000
b=240000
Try: 尝试:
a=`cat file1| sort | uniq | wc -l &`
instead of: 代替:
a=`cat file1| sort | uniq | wc -l` &
Also there are several minor problems: 另外还有几个小问题:
useless cat. 无用的猫。
using backticks instead of $(...) 使用反引号而不是$(...)
no double quotes around variable 变量周围没有双引号
Refactored working version: 重构的工作版本:
#!/bin/bash
a=$(sort file1 | uniq | wc -l &)
b=$(sort file2 | uniq | wc -l &)
wait
echo a="$a"
echo b="$b"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.