This is topic Linux Scripting; How to use printf and awk in forum Books, Films, Food and Culture at Hatrack River Forum.


To visit this topic, use this URL:
http://www.hatrack.com/ubb/main/ultimatebb.php?ubb=get_topic;f=2;t=045810

Posted by Blayne Bradley (Member # 8565) on :
 
Okay I have a script ::NOTE INFORMATION IN TP POST MAY BE OUT OF DATE pls check bottum.::


code:
cat $1 | sort > work

while read l #reads each line of file

do


echo $l
p=$( awk '{print $1}' | cut -c-3 )
q=$( awk '{print $1}' | cut -c-3 )

old=$p$q
x=$old

while grep ''$x'' $2 >&/deu/null

do

cnt = $cnt + 1
x=$old$cnt

done

echo ''$x'' >> $2

done

done < work

2 things I'm no sure what done < work does and this is a script written in emacs how do I run it as a script?

I believe I'm supposed to pass it two files the "clients" file full of surnames and firstnames as $1 and sec as the destination file $2.

[ November 05, 2006, 07:33 PM: Message edited by: Blayne Bradley ]
 
Posted by Blayne Bradley (Member # 8565) on :
 
ok for soemr eason while read line is actualy waiting for a prompt from the user how do I get it to read a line from a file?
 
Posted by Blayne Bradley (Member # 8565) on :
 
Okay my script is 99% done I just need to know why it isn't reading lines from the given file, instead it prompts the user to enter a line.
 
Posted by Blayne Bradley (Member # 8565) on :
 
Okay 'read' l is reading te line i think, but when it gets to the awk command it doesnt work right.
 
Posted by King of Men (Member # 6684) on :
 
Gee, that's a really useful description of the problem. Fortunately for you, by sheer genius I am able to infer from your post what the actual nature of the malfunction is, and can therefore diagnose precisely where in your code the problem lies. And, because I am by nature generous and magnanimous, I shall tell you what the remedy is. Namely, you need to stop doing that thing you're doing wrong, and do it right, instead.
 
Posted by Blayne Bradley (Member # 8565) on :
 
code:
cat clients | sort > work
grep -n '' words > NumDiction
Num=$(grep -c '' NumDiction)

while read l #reads each line of file

do



p=$( echo $l | awk '{print $1}' | cut -c-3 )
q=$( echo $l | awk '{print $1}' | cut -c-3 )

old=$p$q
x=$old

while grep ''$x'' sec >&/deu/null

do

cnt = $cnt + 1
x=$old$cnt

done

a=(perl randm.pl $Num)
b=(perl randm.pl $Num)

d=$(grep '^'$a':' NumDiction | sed 's/[0-9]*://')
e=$(grep '^'$a':' NumDiction | sed 's/[0-9]*://')

Password=$d$e

echo "$l $x $Password >> sec

done

done < work

K I added more to my code.

The purpose of the code is to read lines from ma file notably clints but its supposed o be adaptive for say clients2, clients3 so later I'm going to have to use $1,$2 variables.

When each line is read it will use awk to pipe the first and then the last name to the cut command to get the first 3 characters.

Which will then b parsed together to make a userid.


afte that we chekc for uniqueness with the loop which I'm not sure if it works.


After that we use grep and the random number perl generator to get 2 random words from a dictionary file of 476952 words.

And then we append the line, the userid and then the password to "sec".

But it aint working somewhere.
 
Posted by King of Men (Member # 6684) on :
 
I don't think you can quite have grasped the point I was making in my previous post. Read this, it's useful stuff. Also, are you going to be showing up for CK tonight? I may need to annex England just to keep up with CC and wil.
 
Posted by Blayne Bradley (Member # 8565) on :
 
any chane you can come on ICQ KoM and yes hopefully I will be able to show up.
 
Posted by Blayne Bradley (Member # 8565) on :
 
Okay the problem si that when I run

[linux2-cs.johnabbott.qc.ca]$ bash SecureCase
...


I get a blank, as if tis asking for input.

I am trying to get the read 'l' to read in a while loop each line in the file. But for spome reaosn it is not.
 
Posted by King of Men (Member # 6684) on :
 
First rule of debugging : Put a cout (well, in this case an 'echo') on each line, and figure out where your code is stopping.
 
Posted by Blayne Bradley (Member # 8565) on :
 
i put an echo immediaely AFTER the read l and nodda. same error.

Like it will run until the uniqeness loop if I manually type Blayne, Bradley after I commence the script but thats not supposed to happen its supposed to take the file I pass it and read off each line but it doesnt.

Also I get deu/null no such directory, this is supposed to check if something already exists. I have no idea how it works it is just what my teacher provided.
 
Posted by Blayne Bradley (Member # 8565) on :
 
Argh goddamn ym eyesight I think its >&/dev/null
 
Posted by Blayne Bradley (Member # 8565) on :
 
Okay after the following changes:

while grep "$x" sec >&/dev/null
do

c=$[c+1]
x=$old$c

done

uniqueness appears to work, however i still have the problem where it will only read the line the user enters not the lines provided by the file.
 
Posted by Blayne Bradley (Member # 8565) on :
 
Okay Uniqueness definately DOES work HURRAY Anne Murray!

cat sec

Blayne Bradley BraBla
Blayne Bradley BraBla1
Blayne Bradley BraBla2
Blayne Bradley BraBla3

woot

but password isnt working right.

Made following changes:

a=$(perl randm.pl $Num)
b=$(perl randm.pl $Num)
Okay got random number working again.

Debugging remaining errors.
 
Posted by Blayne Bradley (Member # 8565) on :
 
Okay after realizing I made a typo in my password variable everything WORKS PERFECTELY...


except it reads lines only given by user not from file and I have no clue what the proper syntax is and online + manual isnt helping me.


:EDIT: most up to date code atm.
code:
cat clients | sort > work
grep -n '' words > NumDiction
Num=$(grep -c '' NumDiction)

while read l #reads each line of file

do



p=$( echo $l | awk '{print $1}' | cut -c-3 )
q=$( echo $l | awk '{print $1}' | cut -c-3 )

old=$p$q
x=$old

while grep "$x" sec >&/deu/null

do

c=$[c+1]
x=$old$c

done

a=$(perl randm.pl $Num)
b=$(perl randm.pl $Num)

d=$(grep '^'$a':' NumDiction | sed 's/[0-9]*://')
e=$(grep '^'$a':' NumDiction | sed 's/[0-9]*://')

Password=$d$e

echo "$l $x $Password >> sec

done



[ November 03, 2006, 09:00 PM: Message edited by: Blayne Bradley ]
 
Posted by King of Men (Member # 6684) on :
 
Yes, well. A quick Google tells me that 'read' reads from standard input, ie the keyboard. Try a redirect, thusly:

cat filename | while read l
 


Copyright © 2008 Hatrack River Enterprises Inc. All rights reserved.
Reproduction in whole or in part without permission is prohibited.


Powered by Infopop Corporation
UBB.classic™ 6.7.2