示例:
假设 nowcoder.txt 内容如下:
how they are implemented and applied in computer
how
they
are
and
applied
in说明:
不用担心你输出的空格以及换行的问题
how they are implemented and applied in computer
how they are and applied in
#!/bin/bash
for i in $(cat nowcoder.txt)
do
[ ${#i} -lt 8 ] && echo $i
continue
done
有没有大佬解释一下,不加continue 说我越界或者语法错误,这是为啥
awk '{for(i=1;i<=NF;++i) { if(length($i) < 8) {print $i} }}' nowcoder.txt
sed -i 's/ /\n/g' nowcoder.txt && awk 'length ($0) < 8' nowcoder.txt 大佬们,为啥我这样写系统不通过呢? 我在自己的设备上测出来输出结果明明是一样的,这是为什么呢
awk '
{
s = $0
n = length(s)
l = 1;
for (i = 1; i <= n; i++) {
c = substr(s, i, 1);
if (c !~ /[a-z]/) {
len = i - l
t = substr(s, l, len)
if (len < 8) print(t)
l = i + 1
}
}
last = substr(s, l)
if (length(last) < 8) print(last)
}
' awk '{for(i=1;i<=NF;i++)if(length($i)<8) print $i}'
awk 'BEGIN{RS="[[:space:]]"}length($0)<8 {print}'