在shell脚本的while循环中跳过一行并读取另一行

5

我有一段代码,使用while循环逐行读取文件。在while循环内部,我有一些条件。是否有一种方法可以根据条件跳过当前行并读取下一行?让我更加清晰:

while read Line
do
    //some sample conditions
    a=$Line
    if [ "a" == "b" ]
        //i want to go to the next line from this point. 
done < **inputfile**

非常感谢您的帮助。

2个回答

4

非常感谢scibuff!抱歉回复晚了!你的解决方案很有效! - Parameswar

2
如何呢:
while read Line
do
    # some sample conditions
    a=$Line
    if [ "$a" == "$b" ] # I assume this is not "a" == "b"
        # i want to go to the next line from this point. 
        read Line
        a=$Line
done < **inputfile**

if条件可以是任何内容。我想要的是,根据条件,文件读取应该从下一行开始,并立即执行操作。你给出的脚本将读取下一行,但它只会反映在条件之后的行上。我想要的是,根据条件,下一行应该被读取,并且操作应该从开头开始。 - Parameswar
如果我理解你的评论正确的话,scibuff的回答就是你要找的。你能否花点时间接受它或者评论一下为什么那不是你要找的答案? - Chaitanya

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接