在Bash中循环遍历文件的内容如何迭代文本文件的每一行巴什?使用此脚本:echo "Start!"for p in (peptides.txt)do
echo "${p}"done我在屏幕上看到这个输出:Start!./runPep.sh: line 3: syntax error near unexpected token `('
./runPep.sh: line 3: `for p in (peptides.txt)'(稍后我想做一些更复杂的事情$p而不仅仅是输出到屏幕上。)环境变量壳IS(来自env):SHELL=/bin/bash/bin/bash --version产出:GNU bash, version 3.1.17(1)-release (x86_64-suse-linux-gnu)Copyright (C) 2005 Free Software Foundation, Inc.cat /proc/version产出:Linux version 2.6.18.2-34-default (geeko@buildhost) (gcc version 4.1.2 20061115 (prerelease) (SUSE Linux)) #1 SMP Mon Nov 27 11:46:27 UTC 2006txt文件包含:RKEKNVQ
IPKKLLQK
QYFHQLEKMNVK
IPKKLLQK
GDLSTALEVAIDCYEK
QYFHQLEKMNVKIPENIYR
RKEKNVQ
VLAKHGKLQDAIN
ILGFMK
LEDVALQILL
3 回答
守着一只汪
TA贡献1872条经验 获得超3个赞
备选案文1a:
#!/bin/bashfilename='peptides.txt'echo Startwhile read p; do echo $pdone < $filename
备选案文1b:
#!/bin/bashfilename='peptides.txt'exec 4<$filename echo Startwhile read -u4 p ; do echo $pdone
备选案文2:
#!/bin/bashfilename='peptides.txt'filelines=`cat $filename`echo Startfor line in $filelines ; do echo $linedone
- 3 回答
- 0 关注
- 1609 浏览
添加回答
举报
0/150
提交
取消