Sponsored Content
Top Forums UNIX for Dummies Questions & Answers format output from while read line Post 302176096 by bakunin on Monday 17th of March 2008 10:39:31 AM
Old 03-17-2008
Lets plan the whole thing a little, then it will be easier to understand:

1) we get information chunks and read them in the while-loop bit by bit. We have to set up a data structure to hold all the various pieces of information until we are ready to print it out wholly (to print a line).

2) There should be a certain condition defined for what makes the information "complete": is it that all the various pieces are there? (Have you "fields", which have to be filled and once all are filled the line is complete?) Is a line complete once a certain field is read? (in your case "OS version" is always the last field - is this what you intended or is this just by chance?)

3) What do you do with error conditions? What happens if you read i.e the following lines:

This is my client=2
client version=1.5.6
client version=1.6.7
OS version=6.7

or how about this:

This is my client=2
client version=1.5.6

You should be able to recognize such conditions and handle them somehow. Maybe incomplete records are OK (then you will have to find out somehow when an incomplete record ends), maybe they are not and your script should report an error.

Please answer these questions and then i will proceed to show you how this is implemented.

I hope this helps.

bakunin
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Format a line for output

Hi all I have a problem which requires me to produce a line output in a specified format. I have looked around and see that there is typeset which would do the trick to pad a variable and as such ensure that its start position in a line is always the same. I have tried to use this, however it... (4 Replies)
Discussion started by: jhansrod
4 Replies

2. Shell Programming and Scripting

bash: read file line by line (lines have '\0') - not full line has read???

I am using the while-loop to read a file. The file has lines with null-terminated strings (words, actually.) What I have by that reading - just a first word up to '\0'! I need to have whole string up to 'new line' - (LF, 10#10, 16#A) What I am doing wrong? #make file 'grb' with... (6 Replies)
Discussion started by: alex_5161
6 Replies

3. Shell Programming and Scripting

read line and run a different command according to the output

Hi. I'm trying to write a script that reads a line on a file and runs a different command for a different line output. For example, if it finds the word "Kuku" on the line it sends mail to Kuku@kuku.com. Otherwise, it sends mail to Lulu@lulu.com. TIA. (2 Replies)
Discussion started by: Doojek9
2 Replies

4. Shell Programming and Scripting

Print output and read input on same line

How do I print output and read input on the same line in ksh? echo Hello, what is your name? read name (1 Reply)
Discussion started by: robin_simple
1 Replies

5. Shell Programming and Scripting

Modify a perl line to parse out and output to another format

Hey there... I am looking for a way to take the below contents ( small excerpt) of this file called PTR.csv ptrrecord,0000002e0cc0.homeoffice.anfcorp.com,,10.11.191.62,,,False,62.191.11.10.in-addr.arpa,,302400,default... (6 Replies)
Discussion started by: richsark
6 Replies

6. Shell Programming and Scripting

Read from text file;format and print output

Hi Following is the assumed input... Symmetrix ID : 12345 Originator Port wwn : 123456789 User-generated Name : 123456789/123456789 Sym Dev Dir:P LUN ------ ----- ----------------------- ---- --- ---- ---- ---- ------- 1234 ... (4 Replies)
Discussion started by: maddy.san
4 Replies

7. Shell Programming and Scripting

How to read each line from input file, assign variables, and echo to output file?

I've got a file that looks like this (spaces before first entries intentional): 12345650-000005000GL140227 ANNUAL HELC FEE EN 22345650-000005000GL140227 ANNUAL HELC FEE EN 32345650-000005000GL140227 ANNUAL HELC FEE EN I want to read through the file line by line,... (6 Replies)
Discussion started by: Scottie1954
6 Replies

8. Shell Programming and Scripting

Format next line for ls output

hi i have 4 dir called old-dir1 old-dir2 dir3 dir4 now i need to grep only old dir named ls -d old* > outfileThe output will show as: cat outfile old-dir1 old-dir2Desired output is: old-dir1 old-dir2 (5 Replies)
Discussion started by: raghur77
5 Replies

9. Shell Programming and Scripting

How to read the output of a command line by line and pass it as a variable?

Hi, I have some 2000 names in a table like below. Java Oracle/SQL ANSI SQL SQL,DWH,DB DB&Java And by using for loop in my code i am able to get a single word but if there is any special character or space then it is considering as a next line. I have to execute the below queries in... (10 Replies)
Discussion started by: Samah
10 Replies

10. UNIX for Beginners Questions & Answers

Read line and print output

need help to print the below .. Content of file looks like below .. SCHEMA1. TABLE1 SCHEMA2. TABLE2 SCHEMA3. TABLE3 read lines from above file and print o/p as below print output like read 1st line and print SELECT SCHEMA1.TABLE1 print output like read 2st line and print ... (4 Replies)
Discussion started by: rocking77
4 Replies
xparace(3)							SAORD Documentation							xparace(3)

NAME
XPARace - XPA Race Conditions SYNOPSIS
Potential XPA race conditions and how to avoid them. DESCRIPTION
Currently, there is only one known circumstance in which XPA can get (temporarily) deadlocked in a race condition: if two or more XPA servers send messages to one another using an XPA client routine such as XPASet(), they can deadlock while each waits for the other server to respond. (This can happen if the servers call XPAPoll() with a time limit, and send messages in between the polling call.) The reason this happens is that both client routines send a string to the other server to establish the handshake and then wait for the server response. Since each client is waiting for a response, neither is able to enter its event-handling loop and respond to the other's request. This deadlock will continue until one of the timeout periods expire, at which point an error condition will be triggered and the timed-out server will return to its event loop. Starting with version 2.1.6, this rare race condition can be avoided by setting the XPA_IOCALLSXPA environment variable for servers that will make client calls. Setting this variable causes all XPA socket IO calls to process outstanding XPA requests whenever the primary socket is not ready for IO. This means that a server making a client call will (recursively) process incoming server requests while waiting for client completion. It also means that a server callback routine can handle incoming XPA messages if it makes its own XPA call. The semi-public routine oldvalue=XPAIOCallsXPA(newvalue) can be used to turn this behavior off and on temporarily. Passing a 0 will turn off IO processing, 1 will turn it back on. The old value is returned by the call. By default, the XPA_IOCALLSXPA option is turned off, because we judge that the added code complication and overhead involved will not be justified by the amount of its use. Moreover, processing XPA requests within socket IO can lead to non-intuitive results, since incoming server requests will not necessarily be processed to completion in the order in which they are received. Aside from setting XPA_IOCALLSXPA, the simplest way to avoid this race condition is to multi-process: when you want to send a client mes- sage, simply start a separate process to call the client routine, so that the server is not stopped. It probably is fastest and easiest to use fork() and then have the child call the client routine and exit. But you also can use either the system() or popen() routine to start one of the command line programs and do the same thing. Alternatively, you can use XPA's internal launch() routine instead of system(). Based on fork() and exec(), this routine is more secure than system() because it does not call /bin/sh. Starting with version 2.1.5, you also can send an XPAInfo() message with the mode string "ack=false". This will cause the client to send a message to the server and then exit without waiting for any return message from the server. This UDP-like behavior will avoid the server deadlock when sending short XPAInfo messages. SEE ALSO
See xpa(7) for a list of XPA help pages version 2.1.14 June 7, 2012 xparace(3)
All times are GMT -4. The time now is 04:44 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy