The number of bytes in the unix file per line

I want to count all the lines in a file with a byte in the line greater than the value (say 10). How can i do this?

I tried using cat file | awk'length($0)>10', but it gives me all the lines with char greater than 10. I want to count the bytes in the line.

I wrote the code below, but it does not work. It returns some output of tablets:

#!/bin/ksh
file="a.txt"
while read line
do
    a=`wc -c "${line}"|awk {'print $1'}`
    if [ $a -ne 493]; then
    echo "${line}"
    fi
done <"$file"
+4
source share
1 answer

Your approach is pretty good, just what you need to do a=$(wc -c <<< "$line")or a=$(echo "$line" | wc -w), no need to connect to awk. Also, pay attention to the extra space after 493at if.

Together:

#!/bin/ksh
file="a.txt"
while read line
do
    a=$( echo -n "$line" | wc -c) # echo -n to prevent counting new line
    if [ "$a" -ne 493 ]; then
      echo "${line}"
    fi
done <"$file"
+5
source

Source: https://habr.com/ru/post/1570165/


All Articles