Sponsored Content
Top Forums Shell Programming and Scripting perl how to exit a while loop and quit reading the input file Post 302367844 by subhap on Tuesday 3rd of November 2009 03:56:24 PM
Old 11-03-2009
perl how to exit a while loop and quit reading the input file

I am reading a file using While loop

Code:
while <FILE>
{
  $_ = <FILE>; 
  process data... 

}

I would like to quit reading the file once I encounter a String pattern. How do i do it.

is it
Code:
 if (/SUMMARY/)
 { 
  last; 
 }

I am having problems with uninitialized value in pattern matching and substitution and the while Loop does not end. Don't know how to get around that either..

thanks

Last edited by pludi; 11-03-2009 at 05:29 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reading specific contents from 1 input files and appending it to another input file

Hi guys, I am new to AWK and unix scripting. Please see below my problem and let me know if anyone you can help. I have 2 input files (example given below) Input file 2 is a standard file (it will not change) and we have to get the name (second column after comma) from it and append it... (5 Replies)
Discussion started by: sksahu
5 Replies

2. Shell Programming and Scripting

Perl - pass shell-vars into perl for input loop

I need to process a file line-by-line using some value from a shell variable Something like:perl -p -e 's/$shell_srch/$shell_replace/g' input.txt I can't make the '-s' work in the '-p' or '-n' input loop (or couldn't find a syntaxis.) I have searched and found... (4 Replies)
Discussion started by: alex_5161
4 Replies

3. Shell Programming and Scripting

sed - write remaining input and quit?

I'm an infrequent user of sed. I searched this and other forums and read quite a bit of the O'Reilly book for an answer without luck. In my script I want sed to write the remainder of the input file and quit if it matches a pattern. e.g /Google/ Does anyone have an answer? thank. (5 Replies)
Discussion started by: lyledp
5 Replies

4. Shell Programming and Scripting

Perl Script Not Reading Input Files Correctly

This is one of the strangest things that's happening to me. I'm writing a new Perl script that is trying to read a file. The file is originally in .mof format, but I also saved the contents into a .txt file. As a simple test, I wrote this: #!/user/bin/perl -w use strict; ... (3 Replies)
Discussion started by: kooshi
3 Replies

5. UNIX for Advanced & Expert Users

how to quit or exit from WMToggle

I want directly to move from WMToggle to bash, which command to type? Now I need to type 3 times, :q! etc. any help? its very annoying to time something 3 times continuously :( (1 Reply)
Discussion started by: c_lady
1 Replies

6. Shell Programming and Scripting

Need help with perl script with a while loop reading file

Good morning, I appreciate any assistance that I can get from the monks out there. I am able to get this to work for me so that I can do a hostname lookup if I only specify one hostname in the script. What I want to do is have a file with hostnames and do lookups for each name in the file. Here is... (1 Reply)
Discussion started by: brianjb
1 Replies

7. Shell Programming and Scripting

Difference between exit, bye and quit in sftp

Hi All, I would like to know whether is there any difference in closing the sftp connection with exit, bye and quit. And would like to know the reliable command. (3 Replies)
Discussion started by: Girish19
3 Replies

8. Shell Programming and Scripting

Need to quit out of for loop.

Hi, Here is my code to send read.txt to three servers. col="prd167.mybank.com prd168.mybank.com bsprd169.mybank.com" set -A look $col for IndixList in ${look}; do scp /tmp/read.txt admin@$IndixList:/tmp done This works and all the 3 servers gets the read.txt file. However,... (8 Replies)
Discussion started by: mohtashims
8 Replies

9. Shell Programming and Scripting

Bash Question: HowTo Exit Script with User Input While Process is Running Mid-Loop?

Hi, I have written a script that allows me to repetitively play a music file $N times, which is specified through user input. However, if I want to exit the script before it has finished looping $N times, if I use CTRL+c, I have to CTRL+c however many times are left in order to complete the loop.... (9 Replies)
Discussion started by: hilltop_yodeler
9 Replies

10. Shell Programming and Scripting

ksh loop to read input until QUIT

Hi I'm looking to write a simple ksh loop reading user input (and write it to a file) until the user enters QUIT at which point I want it to continue. Does anyone have an example of this type of loop? Any help much appreciated Cheers (2 Replies)
Discussion started by: Grueben
2 Replies
break(1)                                                           User Commands                                                          break(1)

NAME
break, continue - shell built-in functions to escape from or advance within a controlling while, for, foreach, or until loop SYNOPSIS
sh break [n] continue [n] csh break continue ksh *break [n] *continue [n] DESCRIPTION
sh The break utility exits from the enclosing for or while loop, if any. If n is specified, break n levels. The continue utility resumes the next iteration of the enclosing for or while loop. If n is specified, resume at the n-th enclosing loop. csh The break utility resumes execution after the end of the nearest enclosing foreach or while loop. The remaining commands on the current line are executed. This allows multilevel breaks to be written as a list of break commands, all on one line. The continue utility continues execution of the next iteration of the nearest enclosing while or foreach loop. ksh The break utility exits from the enclosed for, while, until, or select loop, if any. If n is specified, then break n levels. If n is greater than the number of enclosing loops, the outermost enclosing loop shall be exited. The continue utility resumes the next iteration of the enclosed for, while, until, or select loop. If n is specified then resume at the n- th enclosed loop. If n is greater than the number of enclosing loops, the outermost enclosing loop shall be used. On this man page, ksh(1) commands that are preceded by one or two * (asterisks) are treated specially in the following ways: 1. Variable assignment lists preceding the command remain in effect when the command completes. 2. I/O redirections are processed after variable assignments. 3. Errors cause a script that contains them to abort. 4. Words that follow a command preceded by ** that are in the format of a variable assignment are expanded with the same rules as a vari- able assignment. This means that tilde substitution is performed after the = sign, and also that word splitting and file name genera- tion are not performed. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
csh(1), exit(1), ksh(1), sh( 1), attributes(5) SunOS 5.10 17 Jul 2002 break(1)
All times are GMT -4. The time now is 11:11 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy