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
Config::Model::models::LCDd::CFontzPacket(3pm)		User Contributed Perl Documentation	    Config::Model::models::LCDd::CFontzPacket(3pm)

NAME
Config::Model::models::LCDd::CFontzPacket - Configuration class LCDd::CFontzPacket VERSION
version 2.021 DESCRIPTION
Configuration classes used by Config::Model generated from LCDd.conf Elements Model Select the LCD model Optional. Type enum. choice: '533', '631', '633', '635'. upstream_default: '633'. Device Select the output device to use Optional. Type uniline. upstream_default: '/dev/lcd'. Contrast Set the initial contrast Optional. Type integer. upstream_default: '560'. Brightness Set the initial brightness Optional. Type integer. upstream_default: '1000'. OffBrightness Set the initial off-brightness This value is used when the display is normally switched off in case LCDd is inactive. Optional. Type integer. upstream_default: '0'. Reboot Reinitialize the LCD's BIOS on driver start. Optional. Type enum. choice: 'yes', 'no'. upstream_default: 'no'. USB Enable the USB flag if the device is connected to an USB port. For serial ports leave it disabled. Optional. Type enum. choice: 'yes', 'no'. upstream_default: 'no'. OldFirmware Very old 633 firmware versions do not support partial screen updates using 'Send Data to LCD' command(31). For those devices it may be necessary to enable this flag. Optional. Type enum. choice: 'yes', 'no'. upstream_default: 'no'. Size Override the LCD size known for the selected model. Usually setting this value should not be necessary.Optional. Type uniline. default: '20x4'. Speed Override the default communication speed known for the selected model. Default value depends on model Optional. Type enum. choice: '19200', '115200'. SEE ALSO
o cme perl v5.14.2 2012-11-09 Config::Model::models::LCDd::CFontzPacket(3pm)
All times are GMT -4. The time now is 10:45 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy