AWK embeded PERL


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK embeded PERL
# 1  
Old 09-22-2003
Data AWK embeded PERL

Hello Guys,

I am refering to this great forum once again for help.
After various attempts at this, I am still failing to obtain the desire effect.

I have to write a perl script which:
1- reads two values from the user (e.g name & passwd)
2- check each value against a file containing the authentic values
3- redirect the user according to his credentials, e.g
if this user is correctly identified (and granted he/she matches
another criteria), he is then directed to a page that only his
criteria allows him/her.
else (ie credentials incorrect)
user is directed to some error page.


-----------------------------------------------------------------------------

So far I was able to:
open a file in perl
read the content of the file
read the two values ok

however, I don't know how to "awk" each field of the credential file so that I can put each entry inside a separate perl variable, and then check them against the user's ones.

the awk command I am trying to emulate is:
awk -F: '{print $x}' myfile

then I wish to send the content of $x into a perl variable :-(

N.B I realise that this forum is not meant to write me an entire program, and indeed I do not want that, since I actually want to learn how to do this. However I do welcome any help in this direction.


Thanks in advance

Da Bionic one !
# 2  
Old 09-22-2003
Are you trying to pull the content from myfile such as:

awk -F: '{print $1}' myfile

Are you looking output $1 into another file and then use that file as the input of your Perl script? If so, I think that you should be able to:
awk -F: '{print $1}' myfile >> $INPUT

Right? I am still rusty so I am asking as well. Sorry if I am not much help.
# 3  
Old 09-22-2003
AWK embeded perl

Hello Mirv, (and Hello Everyone)

Thanks for your fast response.
I am actually trying to read the content of myfile, somehow.
then from perl, extract fields from each record (file line).

so in normal unix script it looks like the awk script above, but I don't know if I can embed awk inside perl, and if so, how can I ?
otherwise, I am looking at using regular expressions, from perlre, and I found this:

if (/Time: (..) : (..) : (..)/) { # parse out values
$hours = $1;
$minutes = $2;
$seconds = $3;
}


Somehow, this retrieves each (colon separated) time field.
I would like to use something similar in order to retrive my fields.
e.g
myfile should look like this

login passwd credential
toto:totopass:totocred
mama:mamapass:mamacred
didi:didipass:didicred


Inside my perl script, I wish to:
1- open this file in READONLY
2- use some sort of look to scan through each record (file line)
3- retrieve each field, e.g $1 $2 $3
4- store each $x variable inside a perl variable (if the letter retrieving technique is not done in perl)



Many thanks for your efforts
# 4  
Old 09-22-2003
Like I said I am rusty...especially with shell scripting...but that's why I am here! Smilie

So is this going to be a patch process that you are going to be running and that's why you need this info? I'm just curious is all. Now there is another way to get those field you want without awk, it with the cut command. I believe it's cut -c but you can man cut to see all the switches. I am pretty sure that you can use awk inside of Perl. As far as implementing it, you would be better off asking one these gurus here. I think that you can use it just like in a KSH script but not sure. You could always create a test file and test it out, right? Smilie Now do you need to each field ($1, $2, and $3) to go into their own files respectively or would you only one file be enough for you to retreive your info?
# 5  
Old 09-22-2003
AWK embeded PERL

Hello MIRV (and HELLO EVERYONE)

Thanks for your reply.
I believe that you meant a batch, as opposed to a patch process ?
Well, am hoping to use it to secure my website. I have written a html form which prompts the user for his credentials, and then I get the perl script to check the credentials, before redirecting the user to the appropriate page.

I am really not sure how to integrate normal shell commands into a perl script. Earlier I even tried the [echo] command, but it is simply ignored.

Sorry, guys, but this is quite a desperate situation, and I would appreciate some help in this matter. (or at least some pointer)

Many thanks again

sosthene
# 6  
Old 09-23-2003
Yeah I meant batch..hehehe!! Sorry I cannot help man...Like I said before I am trying to get back into the swing of things, so if you find a good fix..please post it for us!


Thanks,
MIRV
# 7  
Old 09-23-2003
Data AWK embeded PERL

Hey guys, just a quick question please:

how can I do this in perl ?

string:
"name : passwd"

retrieve "name" into variable $name
retrieve "passwd" into variable $passwd

This is in short what my problem is.

Many thanks

Da Bionic Fysh
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Converting awk to perl

Hello. I'm currently teaching myself Perl and was trying to turn an awk code that I had written into Perl. I have gotten stuck on a particular part and a2p has not helped me at all. The task was to take a .csv file containing a name, assignment type, score and points possible and compute it into a... (1 Reply)
Discussion started by: Eric7giants
1 Replies

2. Shell Programming and Scripting

Embeded shell variable in command line

Hello, I know this is a situation about the single quote and double literal, but I could not figure out after many search. I need to loop through thousands of different BACs sequencing to optimize kmer individually. IN=/PATH/TO/INPUT/FILES for sample in S{01..1096} do run_program... (9 Replies)
Discussion started by: yifangt
9 Replies

3. Programming

Error in Python Embeded in Qt C++

hi i have an error in script language when run it i use python 2.4, CentOS 5.5, Qt C++ 2010/04 the error is SystemError: null argument to internal routine the Python Code def main(i): print i if __name__ == "__main__": main(i) the C++ Code PyObject *objModule =... (0 Replies)
Discussion started by: HanyM.Magdy
0 Replies

4. Shell Programming and Scripting

awk - to -- PERL

DEAR ALL, i am using following command to fetch some records from more then 50000 files... command is taking more time .... can i have perl command for the same...( i am New to perl ) awk -F "|" '{ if($4==3244898 && $5==5000185) print $66}' *.DATA (2 Replies)
Discussion started by: arvindng
2 Replies

5. Shell Programming and Scripting

awk vs perl

awk -F "|" '{print $2$3$4 upto $30}' file1 > file2 Same logic, i want to write it in perl I tried #!/bin/usr/perl my $line; open FH, "<file1" or die " Can't open file $!"; open FH1, ">file2" or die "Can't open file "; while (<FH1>){ $line = (split /\|/,$_); print FH2 $line;... (3 Replies)
Discussion started by: pritish.sas
3 Replies

6. Shell Programming and Scripting

Using perl grep and awk

I have a script to get server information i wrote in perl because i would like to learn it (and I use it for work). It works great, however i would like to know if there is a good way to reduce the following line. Sean (6 Replies)
Discussion started by: insania
6 Replies

7. Shell Programming and Scripting

awk or perl

hi all I am new to awk/perl I would appreciate it if you could help! how do I read a sub folder and their files. e.g. simulation/10ms/router1.dat, router2.dat,..., router16.dat simulation/100ms/router1.dat, router2.dat,..., router16.dat simulation/300ms/router1.dat,... (14 Replies)
Discussion started by: mmoses
14 Replies

8. Shell Programming and Scripting

problem in embeded command substitution

$ echo $(tty|sed 's#/*/##') pts/0 $ who | grep $(tty|sed 's#/*/##') grep: 0652-033 Cannot open 0551-011. grep: 0652-033 Cannot open Standard. grep: 0652-033 Cannot open input. grep: 0652-033 Cannot open is. grep: 0652-033 Cannot open not. grep: 0652-033 Cannot open a. grep: 0652-033 Cannot... (2 Replies)
Discussion started by: wrl
2 Replies

9. Shell Programming and Scripting

Define an alias with an embeded awk command ??

Hi all, I'm trying to define an alias with an embeded awk command: alias kpipe='kill `psme| grep "ifw -r" | grep -v "grep ifw -r"| awk '{print $2}'`' The problem is that the awk command (awk '{print $2}') contains two ' ..' quotes. So bash assumes that the first awk quote corresponds to... (5 Replies)
Discussion started by: jfortes
5 Replies

10. Shell Programming and Scripting

How to embeded programm within programm

Hi, How to embeded programme within perl programme. Shankarao (2 Replies)
Discussion started by: shankarao
2 Replies
Login or Register to Ask a Question