在Bash中循环浏览文件内容

冷暖自知 提交于 2020-08-09 08:58:08

问题:

How do I iterate through each line of a text file with Bash ? 如何使用Bash遍历文本文件的每一行?

With this script: 使用此脚本:

echo "Start!"
for p in (peptides.txt)
do
    echo "${p}"
done

I get this output on the screen: 我在屏幕上得到以下输出:

Start!
./runPep.sh: line 3: syntax error near unexpected token `('
./runPep.sh: line 3: `for p in (peptides.txt)'

(Later I want to do something more complicated with $p than just output to the screen.) (后来我想用$p来做一些比只输出到屏幕更复杂的事情。)


The environment variable SHELL is (from env): 环境变量SHELL是(来自env):

SHELL=/bin/bash

/bin/bash --version output: /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 output: 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 2006

The file peptides.txt contains: 肽文件.txt文件包含:

RKEKNVQ
IPKKLLQK
QYFHQLEKMNVK
IPKKLLQK
GDLSTALEVAIDCYEK
QYFHQLEKMNVKIPENIYR
RKEKNVQ
VLAKHGKLQDAIN
ILGFMK
LEDVALQILL

解决方案:

参考一: https://stackoom.com/question/6Nni/在Bash中循环浏览文件内容
参考二: https://oldbug.net/q/6Nni/Looping-through-the-content-of-a-file-in-Bash
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!