Sponsored Content
Full Discussion: While read issue...
Top Forums UNIX for Dummies Questions & Answers While read issue... Post 302173775 by Perderabo on Friday 7th of March 2008 07:22:21 PM
Old 03-07-2008
This is crazy. I use double loops just like that all the time. They work fine. Real code example....
Code:
$ cat doubleloop
#! /usr/bin/ksh

while read count ; do
        echo count = $count >temp
        yes some stuff | sed ${count}q >> temp
        while read line ; do
                echo this came from temp file: $line
        done < temp
done < countfile
exit 0
$
$
$
$
$ cat countfile
4
6
2
7
2
$
$
$
$
$
$ ./doubleloop
this came from temp file: count = 4
this came from temp file: some stuff
this came from temp file: some stuff
this came from temp file: some stuff
this came from temp file: some stuff
this came from temp file: count = 6
this came from temp file: some stuff
this came from temp file: some stuff
this came from temp file: some stuff
this came from temp file: some stuff
this came from temp file: some stuff
this came from temp file: some stuff
this came from temp file: count = 2
this came from temp file: some stuff
this came from temp file: some stuff
this came from temp file: count = 7
this came from temp file: some stuff
this came from temp file: some stuff
this came from temp file: some stuff
this came from temp file: some stuff
this came from temp file: some stuff
this came from temp file: some stuff
this came from temp file: some stuff
this came from temp file: count = 2
this came from temp file: some stuff
this came from temp file: some stuff
$

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

While loop read line Issue

Hi I am using while loop, below, to read lines from a very large file, around 400,000 rows. The script works fine until around line 300k but then starts giving incorrect result. I have tried running the script with a smaller data set and it works fine. I made sure to include the line where... (2 Replies)
Discussion started by: saurabhkumar198
2 Replies

2. Shell Programming and Scripting

Multi Line 'While Read' command issue when using sh -c

Hi, I'm trying to run the following command using sh -c ie sh -c "while read EachLine do rm -f $EachLine ; done < file_list.lst;" It doesn't seem to do anything. When I run this at the command line, it does remove the files contained in the list so i know the command works ie... (4 Replies)
Discussion started by: chrispward
4 Replies

3. UNIX for Advanced & Expert Users

read() from ttyS1 issue while write() is Ok

Hi! I've got a problem with reading from serial port, when I run this code on Digi ConnectCore Wi-9c. But writing to serial port is Ok. By the way, when I'm running this code on "full" Linux it is working Ok - I can read and write to serial without mistakes. Where is a problem? uname -a:... (3 Replies)
Discussion started by: Japonomatj
3 Replies

4. Shell Programming and Scripting

while read LINE issue

Hi, This is the script and the error I am receiving Can anyone please suggest ? For the exmaple below assume we are using vg01 #!/bin/ksh echo "##### Max Mount Count Fixer #####" echo "Please insert Volume Group name to check" read VG lvs |grep $VG | awk {'print $1'} > /tmp/audit.log ... (2 Replies)
Discussion started by: galuzan
2 Replies

5. Shell Programming and Scripting

while read issue

I'm using while read in a script to create a file but when I paste on the screen it echos out different than the data. The file is created correctly and the script does as it should. Just trying to resolve what's being show on the screen. while read FILES do echo... (3 Replies)
Discussion started by: toor13
3 Replies

6. Shell Programming and Scripting

Issue in using read keyword twice

Hi, I have a situation where i need to read line by line from a text pad and with each line , i need to take inputs from command line and do some process. Using below code i am not able to use 'read' keyword twice. Can any one please help cat > t.txt a d c > cat > t.ksh while read... (4 Replies)
Discussion started by: Ravindra Swan
4 Replies

7. Shell Programming and Scripting

Read line, issue with leading - and {}'s

Heyas With my forum search term 'issue with leading dash' i found 2 closed threads which sadly didnt help me. Also me was to eager to add the script, that i didnt properly test, and just now figured this issue. So i have this code: if ] then while read line do line="${line/-/'\-'}"... (7 Replies)
Discussion started by: sea
7 Replies

8. Shell Programming and Scripting

ksh while read issue

Hello, I have used a chunk of ksh script similar to this in many places without any issue: while : do print; read OPTION?"Enter a number (q to quit): " expr ${OPTION} + 1 >/dev/null 2>&1 CHECKVAL=$? if }" != ${OPTION} ]; then ... (2 Replies)
Discussion started by: port43
2 Replies

9. Shell Programming and Scripting

File read format issue in UNIX

hi all. my loop is getting failed eventhoug it is 1=1 but it is failure message. any help plz Output expected : echo "sucesss" code out=`cat bit.txt` if ]; then echo "sucess" else echo "Failure" (2 Replies)
Discussion started by: arun888
2 Replies

10. Shell Programming and Scripting

While read pipe input issue

Hello, I have an ffmpeg bash script which is working nice and I need to do the same for other sources. To create new scripts and to deal with multiple bash files sounds not logical. It is a bit hard to manage for me.. I wondered if it was possible to make my input file as variable. Then I... (1 Reply)
Discussion started by: baris35
1 Replies
ZIP_SOURCE_FUNCTION(3)					     Library Functions Manual					    ZIP_SOURCE_FUNCTION(3)

NAME
zip_source_function - create data source from function LIBRARY
libzip (-lzip) SYNOPSIS
#include <zip.h> struct zip_source * zip_source_function(struct zip *archive, zip_source_callback fn, void *userdata); DESCRIPTION
The function zip_source_function creates a zip source from the user-provided function fn, which must be of the following type: typedef zip_int64_t (*zip_source_callback)(void *state, void *data, zip_uint64_t len, enum zip_source_cmd cmd); When called by the library, the first argument is the userdata argument supplied to zip_source_function. The next two arguments are a buf- fer data of size len when data is expected to be returned, or else NULL and 0. The last argument, cmd, specifies which action the function should perform: ZIP_SOURCE_OPEN Prepare for reading. Return 0 on success, -1 on error. ZIP_SOURCE_READ Read data into the buffer data of size len. Return the number of bytes placed into data on success, -1 on error. ZIP_SOURCE_CLOSE Reading is done. Return 0. ZIP_SOURCE_STAT Get meta information for the input data. data points to an initialized which should be filled in. (See zip_stat_init(3). ) Information only available after the source has been read (e.g. size) can be omitted in an earlier call. Return sizeof(struct zip_stat) on success, -1 on error. ZIP_SOURCE_ERROR Get error information. data points to an array of two ints, which should be filled with the libzip error code and the corresponding system error code for the error that occurred. See zip_errors(3) for details on the error codes. Return return(2 * sizeof(int)). ZIP_SOURCE_FREE Clean up and free all resources. Return 0. The library will always issue ZIP_SOURCE_OPEN before issuing ZIP_SOURCE_READ. When it no longer wishes to read from this source, it will issue ZIP_SOURCE_CLOSE. If the library wishes to read the data again, it will issue ZIP_SOURCE_OPEN a second time. If the function is unable to provide the data again, it should return -1. ZIP_SOURCE_STAT can be issued at any time. ZIP_SOURCE_ERROR will only be issued in response to the function returning -1. ZIP_SOURCE_FREE will be the last command issued; if ZIP_SOURCE_OPEN was called and succeeded, ZIP_SOURCE_CLOSE will be called before ZIP_SOURCE_FREE. RETURN VALUES
Upon successful completion, the created source is returned. Otherwise, NULL is returned and the error code in archive is set to indicate the error. ERRORS
zip_source_function fails if: [ZIP_ER_MEMORY] Required memory could not be allocated. SEE ALSO
libzip(3), zip_add(3), zip_replace(3), zip_source_buffer(3), zip_source_file(3), zip_source_filep(3), zip_source_free(3), zip_source_zip(3), zip_stat_init(3) AUTHORS
Dieter Baron <dillo@nih.at> and Thomas Klausner <tk@giga.or.at> NiH March 30, 2009 ZIP_SOURCE_FUNCTION(3)
All times are GMT -4. The time now is 11:53 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy