PDKSH dual std input threads


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting PDKSH dual std input threads
# 1  
Old 06-15-2009
PDKSH dual std input threads

Hi All,

I'm trying to read from two files at the same time, but the second READ is failing, giving no value.

Obvious STDIN is being used by the first "while read", so how can I retrieve a value from a second file within the loop ??

Code:
IFS=" ," 
cat $DATAFILE | while read curdate currentcksum other filename
do
    grep "$filename" $OLDDATAFILE |read olddate oldcksum other
    STATE=DIFFERENT
    if [[ $oldcksum == $currentcksum ]]    
    then
        STATE=SAME
    fi
    echo $filename,$currentcksum,$oldcksum,$STATE
done

$ ./test1.sh
test/Shortcut to UBUSB.exe.lnk,179426984,,DIFFERENT

oldcksum is empty
# 2  
Old 06-15-2009
Quote:
if [[ $oldcksum == $currentcksum ]]
using single =
If still does not work, share the sample input and expected output.
# 3  
Old 06-15-2009
Code:
IFS=" ," 
cat $DATAFILE | while read curdate currentcksum other filename
do
    grep "$filename" $OLDDATAFILE |while read olddate oldcksum other
    STATE=DIFFERENT
    if [[ $oldcksum == $currentcksum ]]    
    then
        STATE=SAME
    fi
    echo $filename,$currentcksum,$oldcksum,$STATE
done

# 4  
Old 06-15-2009
Hi Guys, Thanks for the reply,

rakeshawasthi: == is correct I think, for testing the values.

danmero: The second "read" should be a single line value return, so no while needed (I'll add a head -1 to it at a later point)

The two input files are:

$DATAFILE:
20090615,179426984 454 test/UBUSB.exe.lnk
$OLDDATAFILE:
20090615,179426984 454 test/UBUSB.exe.lnk

So in this case, oldcksum should return the same 179426984, and then the STATE would be set to SAME.

The whole script, is comparing all of the files in the folder and sub-folder to a list generated x days ago. I need to see which cksums have changed.

-----Post Update-----

So I know the first while loop is reading STDIN. What I cant see is how to get a second read-from-file statement to work.

-----Post Update-----

ok - managed to get it working like this:

cat $DATAFILE | while IFS=", " read curdate currentcksum other filename
do
oldcksum=`grep "$filename" $OLDDATAFILE | cut -f1 -d" " | cut -f2 -d","`
STATE=DIFFERENT


Dont know why that convoluted way works..

-----Post Update-----

ok - managed to get it working like this:

cat $DATAFILE | while IFS=", " read curdate currentcksum other filename
do
oldcksum=`grep "$filename" $OLDDATAFILE | cut -f1 -d" " | cut -f2 -d","`
STATE=DIFFERENT


Dont know why that convoluted way works..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Hardware

Fedora 16 dual monitor - dual head - automatic monitor shutdown

Hi, I am experiencing troubles with dual monitors in fedora 16. During boot time both monitors are working, but when system starts one monitor automatically shut down. It happend out of the blue. Some time before when I updated system this happend but then I booted older kernel release and... (0 Replies)
Discussion started by: wakatana
0 Replies

2. Shell Programming and Scripting

password file as std input to script

I'm a fairly new AIX admin (disclaimer). We have SQL scripts written by end users that use a userid and passwd to connect to our DB2 database. Is it possible to create an "input file" that contains the db2 connect parameters and yet secure the file from the SQL creator? i.e., they can "use"... (2 Replies)
Discussion started by: mpheine
2 Replies

3. Shell Programming and Scripting

How to read multiple lines from Std Input into an array

Hi All, Does anyone know how to read multiple lines from standard input into an array and then iterate a loop for all the lines read. Below is an example pseudocode: I need the below filenames to be read by the script into an array or something similar: And then in the script, I... (9 Replies)
Discussion started by: bharath.gct
9 Replies

4. Programming

std::reverse_iterator in Sun C++

Hi, I'm having trouble compling the following code in Sun C++ (under sun studio 10). I found that it is issue with libCstd library. It can be resolved if i used stdport lib. However, i have no choice but to use libCstd. Does anyone know what can be done to resolve the issue? :confused: ... (0 Replies)
Discussion started by: shingpui
0 Replies

5. Shell Programming and Scripting

Help with Getopt::Std

I am working on a script that lists files in a directory with a few file attributes depending on what option the user specifies at the command prompt. The script uses Getopt::Std and takes two switches. The first switch allows the user to specify a directory, the second switch gives a long... (3 Replies)
Discussion started by: Breakology
3 Replies

6. AIX

Redirecting Both to a file and std output

Hello Friends, Can some one help me how to redirect output of a file to both a file and std output? All the help would be greatly appreciated. Regards Sridhar (1 Reply)
Discussion started by: send2sridhar
1 Replies

7. Shell Programming and Scripting

redirecting std error

Hi, I use the following command make all > output-`date +%F-%H-%M-%S`.txt 2>&1 to invoke a MAKE process that takes some weeks to complete. The ouput is redirected to a text file. Now I prefix the above command with time to get time needed for completion of the MAKE process time make... (2 Replies)
Discussion started by: gkamendje
2 Replies

8. Programming

Sun Studio C++ - Getting error in linking std::ostream &std::ostream::operator<<(std:

Hello all Im using CC: Sun C++ 5.6 2004/07/15 and using the -library=stlport4 when linkning im getting The fallowing error : Undefined first referenced symbol in file std::ostream &std::ostream::operator<<(std::ios_base&(*)(std::ios_base&))... (0 Replies)
Discussion started by: umen
0 Replies

9. HP-UX

Set up pdksh

Hi I have Hp UX 11.23 v2 2006 and I want to set up pdksh on it. does it have pdksh on itself? if it does, how can I set it up? but if it doesn't have how can I find it and set it up on my OS? thanks (1 Reply)
Discussion started by: hkoolivand
1 Replies

10. Shell Programming and Scripting

How to redirect std out and std err to same file

Hi I want both standard output and standard error of my command cmd to go to the same file log.txt. please let me know the best commandline to do this. Thanks (2 Replies)
Discussion started by: 0ktalmagik
2 Replies
Login or Register to Ask a Question