Sponsored Content
Top Forums Shell Programming and Scripting awk: Print fields between two delimiters on separate lines and send to variables Post 302684977 by tay9000 on Friday 10th of August 2012 11:57:37 AM
Old 08-10-2012
Sorry, I am a bit new to programming maybe I don't understand the different environments. I am having trouble with this. I am trying to use awk inside of the bash shell on FreeBSD. The "userx" and "domain.com" in my example are of course variable. The source files are in .gz format so I am using zcat to feed the data to the script. I've never tried using an @ sign as a variable so I didn't know that was invalid. But I guess just being able to set the variables like user1='user1@domain', user2='user2@domain.com' would work.

I'll try again later but wanted to put that on the table because I think our scripting environments are different. =P
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

trying to print selected fields of selected lines by AWK

I am trying to print 1st, 2nd, 13th and 14th fields of a file of line numbers from 29 to 10029. I dont know how to put this in one code. Currently I am removing the selected lines by awk 'NR==29,NR==10029' File1 > File2 and then doing awk '{print $1, $2, $13, $14}' File2 > File3 Can... (3 Replies)
Discussion started by: ananyob
3 Replies

2. Shell Programming and Scripting

extract nth line of all files and print in output file on separate lines.

Hello UNIX experts, I have 124 text files in a directory. I want to extract the 45678th line of all the files sequentialy by file names. The extracted lines should be printed in the output file on seperate lines. e.g. The input Files are one.txt, two.txt, three.txt, four.txt The cat of four... (1 Reply)
Discussion started by: yogeshkumkar
1 Replies

3. Shell Programming and Scripting

Compare Tab Separated Field with AWK to all and print lines of unique fields.

Hi. I have a tab separated file that has a couple nearly identical lines. When doing: sort file | uniq > file.new It passes through the nearly identical lines because, well, they still are unique. a) I want to look only at field x for uniqueness and if the content in field x is the... (1 Reply)
Discussion started by: rocket_dog
1 Replies

4. Shell Programming and Scripting

awk print header as text from separate file with getline

I would like to print the output beginning with a header from a seperate file like this: awk 'BEGIN{FS="_";print ((getline < "header.txt")>0)} { if (! ($0 ~ /EL/ ) print }" input.txtWhat am i doing wrong? (4 Replies)
Discussion started by: sdf
4 Replies

5. Shell Programming and Scripting

Print only lines where fields concatenated match strings

Hello everyone, Maybe somebody could help me with an awk script. I have this input (field separator is comma ","): 547894982,M|N|J,U|Q|P,98,101,0,1,1 234900027,M|N|J,U|Q|P,98,101,0,1,1 234900023,M|N|J,U|Q|P,98,54,3,1,1 234900028,M|H|J,S|Q|P,98,101,0,1,1 234900030,M|N|J,U|F|P,98,101,0,1,1... (2 Replies)
Discussion started by: Ophiuchus
2 Replies

6. Shell Programming and Scripting

How to print 1st field and last 2 fields together and the rest of the fields after it using awk?

Hi experts, I need to print the first field first then last two fields should come next and then i need to print rest of the fields. Input : a1,abc,jsd,fhf,fkk,b1,b2 a2,acb,dfg,ghj,b3,c4 a3,djf,wdjg,fkg,dff,ggk,d4,d5 Expected output: a1,b1,b2,abc,jsd,fhf,fkk... (6 Replies)
Discussion started by: 100bees
6 Replies

7. Shell Programming and Scripting

awk sort based on difference of fields and print all fields

Hi I have a file as below <field1> <field2> <field3> ... <field_num1> <field_num2> Trying to sort based on difference of <field_num1> and <field_num2> in desceding order and print all fields. I tried this and it doesn't sort on the difference field .. Appreciate your help. cat... (9 Replies)
Discussion started by: newstart
9 Replies

8. UNIX for Beginners Questions & Answers

How to count lines of CSV file where 2 fields match variables?

I'm trying to use awk to count the occurrences of two matching fields of a CSV file. For instance, for data that looks like this... Joe,Blue,Yes,No,High Mike,Blue,Yes,Yes,Low Joe,Red,No,No,Low Joe,Red,Yes,Yes,Low I've been trying to use code like this... countvar=`awk ' $2~/$color/... (4 Replies)
Discussion started by: nmoore2843
4 Replies

9. Shell Programming and Scripting

awk to print line is values between two fields in separate file

I am trying to use awk to find all the $3 values in file2 that are between $2 and $3 in file1. If a value in $3 of file2 is between the file1 fields then it is printed along with the $6 value in file1. Both file1 and file2 are tab-delimited as well as the desired output. If there is nothing to... (4 Replies)
Discussion started by: cmccabe
4 Replies

10. Shell Programming and Scripting

awk to print lines based on text in field and value in two additional fields

In the awk below I am trying to print the entire line, along with the header row, if $2 is SNV or MNV or INDEL. If that condition is met or is true, and $3 is less than or equal to 0.05, then in $7 the sub pattern :GMAF= is found and the value after the = sign is checked. If that value is less than... (0 Replies)
Discussion started by: cmccabe
0 Replies
AuthenHook(3pm) 					User Contributed Perl Documentation					   AuthenHook(3pm)

NAME
Apache::AuthenHook - Perl API for Apache 2.1 authentication SYNOPSIS
PerlLoadModule Apache::AuthenHook PerlModule My::OtherProvider <Location /digest> Require valid-user AuthType Digest AuthName realm1 AuthDigestProvider My::DigestProvider file My::OtherProvider::digest AuthUserFile realm1 </Location> <Location /basic> Require valid-user AuthType Basic AuthName foorealm AuthBasicProvider My::OtherProvider::basic file My::BasicProvider AuthUserFile realm1 </Location> DESCRIPTION
Apache::AuthenHook offers access to the 2.1 Apache authentication API in Perl. This is different than the authentication API from Apache 1.3 or even Apache 2.0, but in its differences lies strength. For a full description of how authentication works in 2.1, see http://www.serverwatch.com/tutorials/article.php/2202671 Basically, the difference between 2.0 and 2.1 is that authentication is now delegated to providers, and each provider has a specific purpose. For instance, mod_authn_file covers gleaning the password from an .htpasswd or .htdigest file, while mod_auth_basic covers the Basic dialogue between the client and server, regardless of the source of the password. The best part of all this (to me) is that Digest authentication is also delegated out - mod_auth_digest now handles all the intricacies of Digest authentication (including the elusive MSIE support) which means you don't need to worry about them (and neither do I). All that Digest authentication requires is *some* authentication provider to provide user credentials - this can be via mod_authn_file or another mechanism of your choosing. Apache::AuthenHook registers and coordinates the use of Perl handlers as authentication providers. How does this affect you? Read on... EXAMPLE
Say you want to enable Digest authentication in your Apache 2.1 server... PerlLoadModule Apache::AuthenHook <Location /digest> Require valid-user AuthType Digest AuthName realm1 AuthDigestProvider My::DigestProvider file AuthUserFile realm1 </Location> This configuration means that My::DigestProvider will be responsible for providing user credentials for requests to /digest. if My::DigestProvider finds a suitable user, mod_auth_digest will verify those credentials and take care of setting all the proper headers, set the proper HTTP response status, and so on. If My::DigestProvider cannot find a matching user it can decide what to do next - either pass the user to the next provider (in this case the default file provider, which will use the flat file "realm1") or decide that no user means no access. Here is a simple My::DigestProvider use Apache2::Const -compile => qw(OK DECLINED HTTP_UNAUTHORIZED); sub handler { my ($r, $user, $realm, $hash) = @_; # user1 at realm1 is found - pass to mod_auth_digest if ($user eq 'user1' && $realm eq 'realm1') { $$hash = 'eee52b97527306e9e8c4613b7fa800eb'; return Apache2::Const::OK; } # user2 is denied outright if ($user eq 'user2' && $realm eq 'realm1') { return Apache2::Const::HTTP_UNAUTHORIZED; } # all others are passed along to the next provider return Apache2::Const::DECLINED; } isn't that easy? the only thing that is a bit tricky here is $$hash. the fourth argument passed to your handler, $hash, is a reference to to a simple scalar that needs to be populated with the MD5 hash of the user:realm:password combination you determine for the incoming user. this may seem a bit strange, but it is actually exactly how things work over in Apache C land, so I guess that makes it ok. as you can see, returning OK means "user found" and requires that $$hash be populated - mod_auth_digest will take care of determining whether the hash matches the incoming Digest criteria. returning HTTP_UNAUTHORIZED (which is the same as the former and still available AUTH_REQUIRED constant) means "no access." returning DECLINED means "some other provider can try." The steps are remarkably similar for Basic authentication, first <Location /basic> Require valid-user AuthType Basic AuthName foorealm AuthBasicProvider My::BasicProvider file AuthUserFile realm1 </Location> then use Apache2::Const -compile => qw(OK DECLINED HTTP_UNAUTHORIZED); sub handler { my ($r, $user, $password) = @_; # user1/basic1 is ok if ($user eq 'user1' && $password eq 'basic1') { return Apache2::Const::OK; } # user2 is denied outright if ($user eq 'user2') { return Apache2::Const::HTTP_UNAUTHORIZED; } # all others are passed along to the next provider return Apache2::Const::DECLINED; } In the case of Basic authentication, the return codes mean essentially the same thing. The one exception is that OK means that you have checked the user against the password and have found that they match (as opposed to with Digest, where the actual verification is not done by you). These explanations should be enough to get you going - see the files in the test suite for more examples. NOTES
This has been tested under the prefork MPM only, using mostly Perl 5.9.0 (as well as some 5.8.0). It will not work under threaded MPMs - soon, just not yet. FEATURES
/BUGS This is very much so alphaware, so beware - bugs may lurk in unexpected places. there is one bug that is outside of my control, though, and concerns MSIE and Digest authentication for URIs that include query strings. see http://httpd.apache.org/docs-2.0/mod/mod_auth_digest.html one workaround for this issue is is to use POST instead of GET for your forms. A limitation of this interface is that you can't use Perl providers that are not at least two levels deep - the criterion for registering a Perl provider is a simple check for a double-colon. for example, My::Provider will work while Provider won't (although Provider::handler will). anyway, single level handlers are rare, so fixing it would be a lot of trouble for little benefit. AUTHOR
Geoffrey Young <geoff@modperlcookbook.org> COPYRIGHT
Copyright (c) 2003, Geoffrey Young All rights reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself. perl v5.14.2 2005-04-12 AuthenHook(3pm)
All times are GMT -4. The time now is 05:10 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy