Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Skipping a line and reading another line in shell script while loop

i have a code which reads a file line by line using a while loop. Inside the while loop, i have certain conditions. Is there a way using which i can skip the current line and read the next line based upon the condition ? Let me be precise:

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**

Any help would be appreciated.

like image 526
Parameswar Avatar asked Apr 13 '12 11:04

Parameswar


People also ask

How do you skip a line in a shell script?

Using head to get the first lines of a stream, and tail to get the last lines in a stream is intuitive. But if you need to skip the first few lines of a stream, then you use tail “-n +k” syntax. And to skip the last lines of a stream head “-n -k” syntax.

How do you break a while loop in shell script?

Breaking from a while LoopUse the break statement to exit a while loop when a particular condition realizes. The following script uses a break inside a while loop: #!/bin/bash i=0 while [[ $i -lt 11 ]] do if [[ "$i" == '2' ]] then echo "Number $i!" break fi echo $i ((i++)) done echo "Done!"

What is break and continue statement in shell script?

Both “break” and “continue” are used to transfer control of the program to another part of the program. It is used within loops to alter the flow of the loop and terminate the loop or skip the current iteration.

What is break in shell script?

break is a special built-in shell command. In the tcsh shell, break causes execution to resume after the end of the nearest enclosing foreach or while. The remaining commands on the current line are executed. Multilevel breaks are thus possible by writing them all on one line.


1 Answers

Use continue http://www.cyberciti.biz/faq/unix-linux-bsd-appleosx-continue-in-bash-loop/

like image 88
scibuff Avatar answered Sep 27 '22 17:09

scibuff