Sponsored Content
Top Forums Shell Programming and Scripting Shell Script that reads a file Post 302973948 by neutronscott on Tuesday 24th of May 2016 10:03:16 AM
Old 05-24-2016
while executes commands as long as a test succeeds.

read will not succeed at EOF from taskfile.txt and the loop will stop.

if the last line is not in fact a line (it doesn't end with \n), then you will reach EOF before read reaches the delimiter. An example:

Code:
mute@zbox:~$ printf '1\n2\n3' > file
mute@zbox:~$ while read -r a b c; do echo "$a"; done < file
1
2
mute@zbox:~$

Text files by definition should end with a newline, but if this is the problem you need to work around you can try entering your loop again with a test like this:

Code:
mute@zbox:~$ while read -r a b c || [[ $a ]]; do echo "$a"; done < file
1
2
3

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sh script that reads/writes based upon contents of a file

Hi everyone, Ive got a quick question about the feasibility and any suggestions for a shell script. I can use sh or ksh, doesnt matter. Basically, Ive got an output file from a db2 command that looks like so: SCHEMA NAME CARD LEAF ELEAF LVLS ISIZE NDEL KEYS F4 F5 ... (3 Replies)
Discussion started by: rdudejr
3 Replies

2. Shell Programming and Scripting

Shell script that reads from configuration file to get database

Hi intelligent beings, I am trying to write a script that 1. Accepts the following arguments: store_number div_number user_id div_code 2. Will read from a configuration file to get the Database 3. Use the div_code to determine which value to retrieve from the configuration file ... (1 Reply)
Discussion started by: dolo21taf
1 Replies

3. Shell Programming and Scripting

passing argument to shell script that reads user inputs

Hi, Lets say I have a script "ss" which does this read abc echo $abc read pqr echo $pqr Now if I want to pass and argument to only "abc" how do I do it. If I do echo "somevalue" | ss, it does not prompt for pqr and its value comes out as blank. Any help is appreciated Thanks P (6 Replies)
Discussion started by: patjones
6 Replies

4. Shell Programming and Scripting

how to read dbf file in shell script and to convert dbf file usinf shell script

Hi all, I am new to shell scripting. I have dbf file and I need to convert it into csv file. OR, can i read the fields from a .dbf file and OR seprate the records in dbf file and put into .csv or txt. Actually in the .dbf files I am getting , the numbers of fields may vary in very record and... (6 Replies)
Discussion started by: gauara
6 Replies

5. Shell Programming and Scripting

script that reads all the scripts in the directory and run them within that script

Hi I am trying to write a shell script that is reading all the scripts in the current directory (currently 5) and is allowing me to run the scripts that is in the directory. I want that this scripts asks te user to execute 1 of the listed scripts. I have 4 sample scripts in the directory:... (8 Replies)
Discussion started by: I-1
8 Replies

6. Shell Programming and Scripting

script that reads a value and send an email on 89th day

hi all, Currently in my system a user's password expires after 90 days and the last passsword change time is stored in an attribute pwdchange date. i need a linux script that read this attribute and add 89 days and send an email that the user password is expiring the next day. i can store... (1 Reply)
Discussion started by: manankapoor
1 Replies

7. UNIX for Dummies Questions & Answers

Difference between buffered disk reads and cached reads?

I was analyzing the Disk read using hdparm utility. This is what i got as a result. # hdparm -t /dev/sda /dev/sda: Timing buffered disk reads: 108 MB in 3.04 seconds = 35.51 MB/sec # hdparm -T /dev/sda /dev/sda: Timing cached reads: 3496 MB in 1.99 seconds = 1756.56 MB/sec... (1 Reply)
Discussion started by: pinga123
1 Replies

8. Shell Programming and Scripting

Help with script that reads and writes java console Minecraft

Hi I am looking for an easy way to lock game mode (0) for everyone included op on a Minecraft server. It can be a script that every time a player changes game to 1 the script changes back to 0. What the player writes is visible in the java console. I am not good at script programming and my... (0 Replies)
Discussion started by: MyMorris
0 Replies

9. UNIX for Dummies Questions & Answers

Sudo reads password from a .cfg file

cleanwork /saswork removes sas orphanded processes in the saswork directory. Subdirectories under sasem are sas94, sas92 and sasworks . I am getting the following error messages: 1. '/usr/bin/sudo -S apt-get update <~/opt/SiM/pos/ps/db_auth.cfg... (4 Replies)
Discussion started by: dellanicholson
4 Replies

10. Shell Programming and Scripting

Help with Shell Scrip in Masking particular columns in .csv file or .txt file using shell script

Hello Unix Shell Script Experts, I have a script that would mask the columns in .csv file or .txt file. First the script will untar the .zip files from Archive folder and processes into work folder and finally pushes the masked .csv files into Feed folder. Two parameters are passed ... (5 Replies)
Discussion started by: Mahesh G
5 Replies
SAFENET(8)							    NUT Manual								SAFENET(8)

NAME
safenet - Driver for SafeNet compatible UPS equipment NOTE
This man page only documents the hardware-specific features of the safenet driver. For information about the core driver, see nutupsdrv(8). SUPPORTED HARDWARE
This driver supports UPS equipment which can be controlled via SafeNet v1.0 for Windows (serial interface only). EXTRA ARGUMENTS
This driver supports the following optional settings in the ups.conf(5) file: manufacturer=value Autodetection of this parameter is not possible yet (and it probably never will be). Therefore, this user-defined string accepts any name. The default is unknown. modelname=value Like manufacturer above. The default is unknown. serialnumber=value Like manufacturer above. The default is unknown. ondelay=value Time to wait before switching on the UPS (minutes). Defaults to 1 minute. offdelay=value Time to wait before shutting down the UPS (seconds). Defaults to 30 seconds. UPSCMD
This driver supports some instant commands (see upscmd(8)): test.battery.start Start UPS self test test.battery.stop Cancel UPS self test test.failure.start Start simulated power failure test.failure.stop Cancel simulated power failure beeper.enable Enable the UPS beeper beeper.mute Temporarily mute the UPS beeper beeper.toggle Toggle the UPS beeper shutdown.return Turn off the load and wait for the power to return. Uses the timer defined by offdelay. shutdown.reboot Turn off the load and return. Uses the timers defined by offdelay and ondelay. KNOWN PROBLEMS
If you run the shutdown.return command with mains present, the output may stay on or switch off and not back on again. The shutdown.reboot command will unconditionally switch on the load again (with or without mains present). If the driver is called with the -k option (or through upsdrvctl shutdown) it tries to detect which command should be used in an attempt to stay off until mains is present again or to cycle the output if the power returned in the mean time. This isn't bullet-proof, and you should be prepared that the power will either not be shutdown, or that it doesn't return when the power comes back. AUTHOR
Arjen de Korte <adkorte-guest at alioth.debian.org> SEE ALSO
The core driver: nutupsdrv(8) Internet resources: The NUT (Network UPS Tools) home page: http://www.networkupstools.org/ Network UPS Tools 05/21/2012 SAFENET(8)
All times are GMT -4. The time now is 06:22 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy