通过阅读“艰难地学习Python”,我尝试修改练习6,以了解发生了什么。它最初包含:
x = "There are %d types of people." % 10
binary = "binary"
do_not = "don't"
y = "Those who know %s and those who %s." % (binary, do_not)
print "I said: %r." % x
print "I also said: '%s'."
我目前正在尝试列出作为脚本第一个参数传递的目录中所有文件的大小,但是Linux中的-f选项不起作用,或者我遗漏了什么。
以下是代码:
for tmp in "$1/*"
do
echo $tmp
if [ -f "$tmp" ]
then num=`ls -l $tmp | cut -d " " -f5`
echo $num
fi
done
我该怎么解决这个问题?
我在Linux shell中有包含以下详细信息的文件
Sam , apple
jhon , banana
Sam , apple
jhon , banana
Sam , mango
jhon , banana
jhon , apple
Sam , apple
Sam , papaya
使用我的Linux命令,我可以得到如下结果
cat /names/fav.log | cut -d "," -f 1|sort |uniq -c | sort -rn
结果
Sam 5
jhon 4
但我需要第二列的uniq计数。如下所示
Required result
在shell脚本中,我试图将CVS文件转换为Excel2003xml,如下所示:
下面一节讨论如何在Table元素中创建行元素
ROWS=`wc -l < $IN_FILE | sed 's/ //g' `
COLS=`awk -F',' '{print NF; exit}' $IN_FILE`
#for each row in turn, create the elements
for r in {1 to ${ROWS}}
do
echo "<Row>\n" >> $OUT_FI
PFB守则:
for i in 3 4 5 6 7;
do
echo "try $i";
cat vm.txt | cut -f6 -d" " | awk '{ if (NR==$i) print $0 }';
sleep 1;
done;
文件vm.txt包含:
kthr memory page disk faults cpu
r b w swap free re mf pi po fr de sr s0 s1 s2 s3 in sy c