bash for循环打印下面这句话中字母数不大于6的单词。
Bash also interprets a number of multi-character options.
答案:
{{{密码回复可见}}}
Bash also interprets a number of multi-character options.
答案:
{{{密码回复可见}}}
0
#!/bin/bsah
#print
for i in Bash also interprets a number of multi-character options ; do
n=`echo $i|wc -c`
if [ $n -lt 6 ]; then
echo $i
fi
done
for i in Bash also interprets a number of multi-character options ; do
n=`echo $i|wc -c`
if [ $n -lt 6 ]; then
echo $i
fi
done
0
本帖最后由 ocean 于 2014-9-17 21:34 编辑
[root@OceanV sh]# cat printnum.sh
#/bin/bash
#for循环打印下面这句话中字母数不大于6的单词。
for i in Bash also interprets a number of multi-character options;do
m=`echo -n $i | wc -c`
if [[ $m -le 6 ]];then
echo $i
fi
done
[root@OceanV sh]# cat printnum.sh
#/bin/bash
#for循环打印下面这句话中字母数不大于6的单词。
for i in Bash also interprets a number of multi-character options;do
m=`echo -n $i | wc -c`
if [[ $m -le 6 ]];then
echo $i
fi
done
0
for i in `echo "Baoh also interprets a number of multi-character options"`; do
a=`echo $i| wc -c`
if [ $a -le 7 ]; then
echo $i
fi
done
a=`echo $i| wc -c`
if [ $a -le 7 ]; then
echo $i
fi
done
0
#!/bin/bash
for i in Bash also interprets a number of multi-character options
do
length=${#i}
if [ $length -lt 7 ];then
echo $i
fi
done
for i in Bash also interprets a number of multi-character options
do
length=${#i}
if [ $length -lt 7 ];then
echo $i
fi
done
0
#!/bin/bash
## This script is for listing words which letter number less than 6 in a sentence.
## Writed by Louis on 2014/08/31 11:40
s='Bash also interprets a number of multi-character options'
for i in $s; do
y=`expr length "$i"`
if [ $y -le 6 ]; then
echo $i
fi
done
#!/bin/bash
## This script is for listing words which letter number less than 6 in a sentence.
## Writed by Louis on 2014/08/31 11:40
s='Bash also interprets a number of multi-character options'
for i in $s; do
y=`expr length "$i"`
if [ $y -le 6 ]; then
echo $i
fi
done
0
for i in Bash also interprets a number of multi-character optionsn ;do
length=`echo $i |wc -m`
if [ $length -le 7 ] ;then
echo "$i"
fi
done
length=`echo $i |wc -m`
if [ $length -le 7 ] ;then
echo "$i"
fi
done
0
- #!/bin/bash
- string=`echo "Bash also interprets a number of multi-character options."`
- num=`echo "$string"|awk '{print NF}'`
- for i in `seq 1 $num` ;do
- a=`echo "$string"|awk '{print $i'}'`
- j=`echo "$string"|awk '{print $i'}'|cut -c7`
- if [ -z $j ];then
- echo $a
- fi
- done
0
#!/bin/bash
word=(Bash also interprets a number of multi-character options)
for i in ${word[@]}
do
size=`echo -n $i | wc -m`
if [ $size -le 6 ];then
echo $i
fi
done
word=(Bash also interprets a number of multi-character options)
for i in ${word[@]}
do
size=`echo -n $i | wc -m`
if [ $size -le 6 ];then
echo $i
fi
done
0
#!/bin/bash
#
for i in Bash also interprets a number of multi-character optionsn ;do
words=`echo $i|wc -m `
if [ $words -le 7 ] ; then
echo $i
fi
done
#
for i in Bash also interprets a number of multi-character optionsn ;do
words=`echo $i|wc -m `
if [ $words -le 7 ] ; then
echo $i
fi
done
0
- #!/bin/bash
- #Print no more than the number of letters of words 6
- #2015/05/15
- for i in Bash also interprets a number of multi-character options.
- do
- s=`echo $i | wc -c`
- if [ "$s" -lt 6 ]
- then
- echo $i
- fi
- done
0
本帖最后由 21emerald 于 2015-7-23 23:36 编辑
#!/bin/bash
for i in "Bash also interprets a number of multi-character options"
do
num=`echo $i|wc -c`
[ "$num" -le "6" ] && echo "$i"
done
改:
for i in Bash also interprets a number of multi-character options
#!/bin/bash
for i in "Bash also interprets a number of multi-character options"
do
num=`echo $i|wc -c`
[ "$num" -le "6" ] && echo "$i"
done
改:
for i in Bash also interprets a number of multi-character options
0
aa="Bash also interprets a number of multi-character options"
for i in `echo $aa`
do
n=`echo $i | wc -c`
if [ $n -le 7 ];then
echo $i
fi
done
aa="Bash also interprets a number of multi-character options"
for i in `echo $aa`
do
n=`echo $i | wc -c`
if [ $n -le 7 ];then
echo $i
fi
done
0
- #!/usr/bin/env python
- # coding=utf-8
- with open('/home/wangdi/ceshi.txt') as f:
- for line in f:
- for word in line.split():
- if len(word) <= 6:
- print word,
0
#!/bin/bsah
#print
for i in Bash also interprets a number of multi-character options ; do
n=`echo $i|wc -c`
if [ $n -lt 6 ]; then
echo $i
fi
done
for i in Bash also interprets a number of multi-character options ; do
n=`echo $i|wc -c`
if [ $n -lt 6 ]; then
echo $i
fi
done
0
- a=(Bash also interprets a number of multi-character options)
- for i in ${a[*]}
- do
- b=`echo $i |wc -m`
- if [ $b -le 6 ];then
- echo $i=$b
- fi
- done
0
n='Bash also interprets a number of multi-character options.'
for m in $n;do
k=`echo $m|wc -m`
if [ $k -le 6 ];
then
echo $m >> 3.txt
else
continue
fi
done
for m in $n;do
k=`echo $m|wc -m`
if [ $k -le 6 ];
then
echo $m >> 3.txt
else
continue
fi
done
0
本帖最后由 蓝色风暴 于 2015-12-24 11:06 编辑
#!/bin/bash
for i in `grep -oE '\b[[:alpha:]]{1,6}\b' /root/1.txt`
do
num=`echo $i | wc -c`
if [ $num -le 6 ];then
echo "$i"
fi
done
#!/bin/bash
for i in `grep -oE '\b[[:alpha:]]{1,6}\b' /root/1.txt`
do
num=`echo $i | wc -c`
if [ $num -le 6 ];then
echo "$i"
fi
done
0
本帖最后由 hlymlv 于 2016-1-7 15:40 编辑
看看#!/bin/bash
w=`cat /root/1.txt|wc -w`
for i in `seq 1 $w`
do
m=`cat /root/1.txt|tr ' ' '\n'|sed -n "$i"p|sed 's/\.//g'`
n=`expr length $m`
if [ "$n" -le 6 ];then
echo $m
fi
done
看看#!/bin/bash
w=`cat /root/1.txt|wc -w`
for i in `seq 1 $w`
do
m=`cat /root/1.txt|tr ' ' '\n'|sed -n "$i"p|sed 's/\.//g'`
n=`expr length $m`
if [ "$n" -le 6 ];then
echo $m
fi
done
0
#!/bin/sh
for u in `echo "Bash also interprets a number of multi-character options."`
do
i=`echo $u |wc -m`
if [ $i -le 7 ];then
echo $u
fi
done
for u in `echo "Bash also interprets a number of multi-character options."`
do
i=`echo $u |wc -m`
if [ $i -le 7 ];then
echo $u
fi
done
0
for i in `echo "Baoh also interprets a number of multi-character options"`; do
a=`echo $i| wc -c`
if [ $a -le 7 ]; then
echo $i
fi
done
for i in `echo "Baoh also interprets a number of multi-character options"`; do
a=`echo $i| wc -c`
if [ $a -le 7 ]; then
echo $i
fi
done
0
本帖最后由 loveyouhyf 于 2016-1-7 22:36 编辑
奇怪了,如上中的number也是不大于6个字符,为什么没显示出来呢?
看看下面这个也许就明白了
[root@bbs ~]# for s in Bash; do n=`echo $s|wc -c`; if [ ! $n -gt 7 ]; then echo $s;fi; done|wc -c
5
因此这个应改为
for s in Bash also interprets a number of multi-character options; do n=`echo $s|wc -c`; if [ ! $n -gt 7 ]; then echo $s;fi; done
- [root@bbs ~]# for s in Bash also interprets a number of multi-character options; do n=`echo $s|wc -c`; if [ ! $n -gt 6 ]; then echo $s;fi; done
- Bash
- also
- a
- of
看看下面这个也许就明白了
[root@bbs ~]# for s in Bash; do n=`echo $s|wc -c`; if [ ! $n -gt 7 ]; then echo $s;fi; done|wc -c
5
因此这个应改为
for s in Bash also interprets a number of multi-character options; do n=`echo $s|wc -c`; if [ ! $n -gt 7 ]; then echo $s;fi; done
0
本帖最后由 沧海一叶 于 2016-1-9 09:44 编辑
#!/bin/bash
#
for i in "Bash also interprets a number of multi-character options";do
if [ `wc -c $i > 6` ]; then
echo $i
fi
done
#!/bin/bash
#
for i in "Bash also interprets a number of multi-character options";do
if [ `wc -c $i > 6` ]; then
echo $i
fi
done
0
#!/bin/bash
for i in Bash also interprets a number of multi-character optionsn
do
words=`echo $i | sed -r 's/[^a-zA-Z]//g' |wc -m`
if [ $words -le 7 ]
then
echo "$i"
fi
done
for i in Bash also interprets a number of multi-character optionsn
do
words=`echo $i | sed -r 's/[^a-zA-Z]//g' |wc -m`
if [ $words -le 7 ]
then
echo "$i"
fi
done
0
- #! /bin/bash
- ##
- word='Bash also interprets a number of multi-character options.'
- for i in $word
- do
- if [ `echo $i|wc -L` -le 6 ];then
- echo $i
- fi
- done
0
for i in Bash also interprets a number of multi-character options
do
n=`echo $i|wc -L`
if [ $n -le 6 ]
then
echo $i
fi
done
do
n=`echo $i|wc -L`
if [ $n -le 6 ]
then
echo $i
fi
done
0
cat awk_input | awk '{for(i=0;i<=NF;i++) {if(length($i)>=6) {print $i}}}'
[root@Global ~]# cat awk_input
sh also interprets a number of multi-character options.
[root@Global ~]# cat awk_input
sh also interprets a number of multi-character options.
编辑回复