English 中文(简体)
我的管道是向一个阵列输出吗?
原标题:Can I pipe ispell output to an array?

我需要从某种方面获得原产地——l到——的输出,我可以通过这些产出。

至今为止

cat $1 | ispell -l

我试图按行文将其读成一个阵列,但该团为我工作。

是否有任何建议?

问题回答

这实际上比迄今提供的任何答复要容易得多。 您无需打上任何外部双版,例如<条码>。 或做任何 lo。

简单:

array=( $(ispell -l < $1) )

最新目录有<条码>地图册或<条码>>>> 阅读<>

   readarray stuff < <(ispell -l < "$1")
   echo "number of lines: ${#stuff[@]}"

(this example returns effectively ispell -l < "$1"|wc -l)

由于由于管道的缘故,读书会放在一个小星上,所以它赢得了笔工作。 仅使用投入。


   mapfile [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [-c quantum] [array]
   readarray [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [-c quantum] [array]
          Read lines from the standard input into the indexed array variable array, or from file descriptor fd if the -u option is supplied.  The vari‐
          able MAPFILE is the default array.  Options, if supplied, have the following meanings:
          -n     Copy at most count lines.  If count is 0, all lines are copied.
          -O     Begin assigning to array at index origin.  The default index is 0.
          -s     Discard the first count lines read.
          -t     Remove a trailing newline from each line read.
          -u     Read lines from file descriptor fd instead of the standard input.
          -C     Evaluate callback each time quantum lines are read.  The -c option specifies quantum.
          -c     Specify the number of lines read between each call to callback.

          If  -C  is specified without -c, the default quantum is 5000.  When callback is evaluated, it is supplied the index of the next array element
          to be assigned as an additional argument.  callback is evaluated after the line is read but before the array element is assigned.

          If not supplied with an explicit origin, mapfile will clear array before assigning to it.

          mapfile returns successfully unless an invalid option or option argument is supplied, array is invalid or unassignable, or if array is not an
          indexed array.

There is no such thing as an array in shell. (Bash and zsh have array extensions; but if you find yourself thinking that a bash 或 a zsh extension would be helpful f或 a script, the c或rect choice is instead to rewrite in perl 或 python. /digression)

你们实际上想要的是这些建筑之一:

ispell -l < "$1" | while read line; do
    ... take action on "$line" ...
done

f或 w或d in $(ispell -l < "$1"); do
    ... take action on "$w或d" ...
done

I would need to know m或e about what you re trying to do and about the output f或mat of ispell -l (I don t have it installed and don t have time right now to build it) to tell you which of the above is the right option.

#!/bin/bash

declare -a ARRAY_VAR=(`cat $1 | ispell -l`)

for var in ${ARRAY_VAR[@]}
do
    place your stuff to loop with ${VAR} here
done

页: 1

ispell -l $file | awk  
{
  print "Do something with $0"
  #Or put to awk array
  array[c++]=$0
}
END{
  print "processing the array here if you want"
  for(i=1;i<=c;i++){
     print i,array[i]
  }
}
 

Awk通过档案进行检索的性能优于批次。





相关问题
KornShell- Creating a fixed width text file

I need to create a simple fixed width text file in KornShell (ksh). My current attempt using printf to pad the string isn t working out very well. What s the shortest, cleanest way to create a fixed ...

unix find command

how to use the find command to find files/directories which are not matching the pattern. for eg: find <some options > -name "dontfile.txt" should give me output of all the find whose file ...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

Case insensitive comparison of strings in shell script

The == operator is used to compare two strings in shell script. However, I want to compare two strings ignoring case, how can it be done? Is there any standard command for this?

1. 露台式照像

在Windows XP中,没有一时出现指挥时,是否有办法操作一种灰色文字? 我常常需要把“善待”(工作)与“灰色”同起来,即使我的文字没有产出,......

热门标签