从在bash WC得到的只是整 [英] get just the integer from wc in bash

查看:130
本文介绍了从在bash WC得到的只是整的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让WC在bash返回整数?

Is there a way to get the integer that wc returns in bash?

基本上我想要的文件名之后写的行号数和字数统计到屏幕上。

Basically I want to write the line numbers and word counts to the screen after the file name.

输出:文件名linecount单词计数
这是我到目前为止有:

output: filename linecount wordcount Here is what I have so far:

files=`ls`
for f in $files;
do
        if [ ! -d $f ] #only print out information about files !directories
        then
                # some way of getting the wc integers into shell variables and then printing them
                echo "$f $lines $ words"
        fi
done

推荐答案

您可以使用 削减 命令得到的只是的第一个字WC 的输出(这是该行或字数):

You can use the cut command to get just the first word of wc's output (which is the line or word count):

lines=`wc -l $f | cut -f1 -d' '`
words=`wc -w $f | cut -f1 -d' '`

这篇关于从在bash WC得到的只是整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆