Sponsored Content
Full Discussion: read inside a while loop
Top Forums UNIX for Dummies Questions & Answers read inside a while loop Post 72539 by zazzybob on Saturday 21st of May 2005 10:53:27 AM
Old 05-21-2005
Rather than wrestling with the shell to do this - make it easy on yourself and use Perl - for example, to only print the line if the user enters a 1....
Code:
#!/usr/bin/perl

open( FOOFILE, "< foofile" );
while( <FOOFILE> ) {
  print( "Enter a number: " );
  chomp( $input = <STDIN> );
  if ( $input == 1 ) {
    print( "You entered a 1 and the line is $_" );
  } else {
    print( "Ooops - not a 1\n" );
  }
}
close( FOOFILE );

Cheers
ZB
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

input inside while read loop

Hi all Does anyone have a script that will allow me to stop inside a while read loop. I want to pause the loop until a enter is pressed. e.g. While read line do echo something if LINECOUNT > 40 then read ENTER?"PRESS ENTER TO CONT..." ... (3 Replies)
Discussion started by: jhansrod
3 Replies

2. Shell Programming and Scripting

read command (input) inside the while loop

Hi, 'read' command is not working inside the while loop, How can I solve this? Rgds, Sharif. (2 Replies)
Discussion started by: sharif
2 Replies

3. Shell Programming and Scripting

Using variables created sequentially in a loop while still inside of the loop [bash]

I'm trying to understand if it's possible to create a set of variables that are numbered based on another variable (using eval) in a loop, and then call on it before the loop ends. As an example I've written a script called question (The fist command is to show what is the contents of the... (2 Replies)
Discussion started by: DeCoTwc
2 Replies

4. Shell Programming and Scripting

BASH loop inside a loop question

Hi all Sorry for the basic question, but i am writing a shell script to get around a slightly flaky binary that ships with one of our servers. This particular utility randomly generates the correct information and could work first time or may work on the 12th or 100th attempt etc !.... (4 Replies)
Discussion started by: rethink
4 Replies

5. Shell Programming and Scripting

Update file record inside read loop

Hi, I am reading file records inside a while loop, and want to update the record when certain condition is met. How can I update a file while being read? I want to avoid using temporary files, copy, rename, ... while IFS=',' read -r f1 f2 do function(f1,f2) if then <add... (1 Reply)
Discussion started by: ysrini
1 Replies

6. Shell Programming and Scripting

For loop inside awk to read and print contents of files

Hello, I have a set of files Xfile0001 - Xfile0021, and the content of this files (one at a time) needs to be printed between some line (lines start with word "Generated") that I am extracting from another file called file7.txt and all the output goes into output.txt. First I tried creating a for... (5 Replies)
Discussion started by: jaldo0805
5 Replies

7. UNIX for Dummies Questions & Answers

Write a while loop inside for loop?

I'm taking a unix class and need to countdown to 0 from whatever number the user inputs. I know how to do this with a while or until loop but using the for loop is throwing me off.... I know I can use an if-then statement in my for loop but can I include a while loop in my for loop? (3 Replies)
Discussion started by: xxhieixx
3 Replies

8. Shell Programming and Scripting

Bash - How to do a "read -p" inside a while loop?

Hi there guys! I was trying to do: while read line; do if ; then read -p "Press Enter to continue..." cont=0 fi echo $line let cont++ done < file.txt However, I have read that the read -p would not work in a while loop... I was wondering if there is any other way to... (2 Replies)
Discussion started by: rplae
2 Replies

9. Shell Programming and Scripting

Unable to read user input inside a loop

Hi, This query is a part of a much more lengthy script. I wish to look for all the files in a folder named "data" which in this case has two files i.e. plan.war and agent.properties. For all the files found under data I wish to ask the user as to where they wish copy the files to. Below,... (14 Replies)
Discussion started by: mohtashims
14 Replies

10. Shell Programming and Scripting

Failure: if grep "$Var" "$line" inside while read line loop

Hi everybody, I am new at Unix/Bourne shell scripting and with my youngest experiences, I will not become very old with it :o My code: #!/bin/sh set -e set -u export IFS= optl="Optl" LOCSTORCLI="/opt/lsi/storcli/storcli" ($LOCSTORCLI /c0 /vall show | grep RAID | cut -d " "... (5 Replies)
Discussion started by: Subsonic66
5 Replies
lpq(1B) 					     SunOS/BSD Compatibility Package Commands						   lpq(1B)

NAME
lpq - display the content of a print queue SYNOPSIS
/usr/ucb/lpq [-P destination] [-l] [ + [interval]] [ request-ID...] [user...] DESCRIPTION
The lpq utility displays the information about the contents of a print queue. A print queue is comprised of print requests that are waiting in the process of being printed. lpq displays the following information to the standard output: o the username of the person associated with a print request, o the position of a print request in the print queue, o the name of file or files comprising a print request, o the job number of a print request, and o the size of the file requested by a print request. File size is reported in bytes. Normally, only as much information as will fit on one line is displayed. If the name of the input file associated with a print request is not available, the input file field indicates the standard input. The print client commands locate destination information using the printers database in the name service switch. See nsswitch.conf(4), printers(4), and printers.conf(4) for details. OPTIONS
The following options are supported: -P destination Displays information about printer or class of printers (see lpadmin(1M)) . Specify destination using atomic or POSIX-style (server:destination) names. See printers.conf(4) for information regarding the naming conventions for atomic names and standards(5) for information regarding POSIX. -l Displays information in long format. Long format includes the name of the host from which a print request originated in the display. + [interval] Displays information at specific time intervals. Stops displaying information when the print queue is empty. Clears the screen before reporting displaying the print queue. Specify interval as the number of seconds between displays. If inter- val is not specified only executes once. OPERANDS
The following operands are supported: request-ID The job number associated with a print request. user The name of the user about whose jobs lpq reports information. Specify user as a valid username. EXIT STATUS
The following exit values are returned: 0 Successful completion. non-zero An error occurred. FILES
/var/spool/print/[cd]f* Spooling directory and request files for jobs awaiting transfer. /var/spool/lp/* LP print queue $HOME/.printers User-configurable printer database /etc/printers.conf System printer configuration database printers.conf.byname NIS version of /etc/printers.conf printers.org_dir NIS+ version of /etc/printers.conf ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWscplp | +-----------------------------+-----------------------------+ SEE ALSO
lp(1), lpc(1B), lpr(1B), lprm(1B), lpstat(1), lpadmin(1M), nsswitch.conf(4), printers(4), printers.conf(4), attributes(5), standards(5) SunOS 5.10 23 May 2003 lpq(1B)
All times are GMT -4. The time now is 04:22 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy