FacebookTwitter
Hatrack River Forum   
my profile login | search | faq | forum home

  next oldest topic   next newest topic
» Hatrack River Forum » Active Forums » Books, Films, Food and Culture » Linux Scripting; How to use printf and awk

   
Author Topic: Linux Scripting; How to use printf and awk
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
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 ]

IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
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?
IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
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.
IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
Okay 'read' l is reading te line i think, but when it gets to the awk command it doesnt work right.
IP: Logged | Report this post to a Moderator
King of Men
Member
Member # 6684

 - posted      Profile for King of Men   Email King of Men         Edit/Delete Post 
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.
Posts: 10645 | Registered: Jul 2004  |  IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
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.

IP: Logged | Report this post to a Moderator
King of Men
Member
Member # 6684

 - posted      Profile for King of Men   Email King of Men         Edit/Delete Post 
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.
Posts: 10645 | Registered: Jul 2004  |  IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
any chane you can come on ICQ KoM and yes hopefully I will be able to show up.
IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
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.

IP: Logged | Report this post to a Moderator
King of Men
Member
Member # 6684

 - posted      Profile for King of Men   Email King of Men         Edit/Delete Post 
First rule of debugging : Put a cout (well, in this case an 'echo') on each line, and figure out where your code is stopping.
Posts: 10645 | Registered: Jul 2004  |  IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
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.

IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
Argh goddamn ym eyesight I think its >&/dev/null
IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
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.

IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
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.

IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
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 ]

IP: Logged | Report this post to a Moderator
King of Men
Member
Member # 6684

 - posted      Profile for King of Men   Email King of Men         Edit/Delete Post 
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

Posts: 10645 | Registered: Jul 2004  |  IP: Logged | Report this post to a Moderator
   

   Close Topic   Feature Topic   Move Topic   Delete Topic next oldest topic   next newest topic
 - Printer-friendly view of this topic
Hop To:


Contact Us | Hatrack River Home Page

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