Sponsored Content
Top Forums UNIX for Advanced & Expert Users Combining awk Inline and File Code Post 302897169 by Akshay Hegde on Friday 11th of April 2014 12:16:59 PM
Old 04-11-2014
Whether this is what you are looking for ?

Code:
akshay@Aix:/tmp$ cat a.awk 
function test(text){
print text
}

akshay@Aix:/tmp$ awk -f a.awk  --source 'BEGIN{test("Test me")}'
Test me

This User Gave Thanks to Akshay Hegde For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed / awk - inplace or inline edit

I need to remove the '&' from a file. In each line of the file, the fields are separated by ^K. I only want to remove '&' if it exists in field number 9. (example of field 9: abc&xyz) I need to do an in place/in line edit. So far I have accomplished the following: awk -F '^K' '{print... (6 Replies)
Discussion started by: hemangjani
6 Replies

2. Shell Programming and Scripting

Inline searc and replace inside file

Hello, I have a text file that i want to redirect into a new file , searching and replacing certain string during the opertaion. This should be done using shell script , so it should not be interactive. The script should get four parameters : source file target file source string target... (1 Reply)
Discussion started by: yoavbe
1 Replies

3. Post Here to Contact Site Administrators and Moderators

inline code tags

How to add inline tags in the posts? Like in this thread post #4. Thanks. (5 Replies)
Discussion started by: clx
5 Replies

4. UNIX for Advanced & Expert Users

awk - remove block of text, multiple actions for 'if', inline edit

I'm having a couple of issues. I'm trying to edit a nagios config and remove a host definition if a certain "host_name" is found. My thought is I would find host definition block containing the host_name I'm looking for and output the line numbers for the first and last lines. Using set, I will... (9 Replies)
Discussion started by: mglenney
9 Replies

5. Shell Programming and Scripting

Inline edit using sed / awk

Hi, I have file with all the lines as following format <namebindings:StringNameSpaceBinding xmi:id="StringNameSpaceBinding" name="ENV_CONFIG_PATH" nameInNameSpace="COMP/HOD/MYSTR/BACKOFFICE/ENV_CONFIG_PATH" stringToBind="test"/> I want to replace (all the lines) value of... (8 Replies)
Discussion started by: shuklaa02
8 Replies

6. Programming

Perl : Inline program to determine file size

Hi, I have 5 files as below $ ll sam* -rw-rw-rw- 1 sam ugroup 0 Mar 21 06:06 sam3 -rw-rw-rw- 1 sam ugroup 0 Apr 3 22:41 sam2 -rw-rw-rw- 1 sam ugroup 17335 Apr 10 06:07 sam1 -rw-rw-rw- 1 sam ugroup 5 Apr 10 07:53 sam5 -rw-rw-rw- 1 sam ugroup 661 Apr 10 08:16 sam4 I want to list out... (4 Replies)
Discussion started by: sam05121988
4 Replies

7. Shell Programming and Scripting

awk problem - combining awk statements

i have a datafile that has several lines that look like this: 2,dataflow,Sun Mar 17 16:50:01 2013,1363539001,2990,excelsheet,660,mortar,660,4 using the following command: awk -F, '{$3=strftime("%a %b %d %T %Y,%s",$3)}1' OFS=, $DATAFILE | egrep -v "\-OLDISSUES," | ${AWK} "/${MONTH} ${DAY}... (7 Replies)
Discussion started by: SkySmart
7 Replies

8. Shell Programming and Scripting

How to extract xml attribute values using awk inline.?

I am trying to extract specific XML attribute values for search pattern <factories.*baseQueueName' from resources.xml. my scripts works ok,, but to extract 3 values this code does echo $line three times, it could be 'n' times. How can I use awk to extract matching pattern values in-line or... (11 Replies)
Discussion started by: kchinnam
11 Replies

9. Shell Programming and Scripting

Lookup in another file and conditionally modify it inline

Hi, I have an issue where i need to lookup in a given transaction file and if the same transaction is found in another file, then i need to replace a few columns with some other value. Finally, the changed and unchanged lines must be printed and stored in the same source file. for example... (5 Replies)
Discussion started by: mansoorcfc
5 Replies

10. Shell Programming and Scripting

Combining awk code into one

the following code works perfectly for me: # AWK 1 gawk -F, '/,'${ThisMonthDOW}' '${ThisMonthMON}' :: '${ThisMonthYEA}',/ { if (NF == 10) ... (6 Replies)
Discussion started by: SkySmart
6 Replies
Test::Object(3) 					User Contributed Perl Documentation					   Test::Object(3)

NAME
Test::Object - Thoroughly testing objects via registered handlers SYNOPSIS
################################################################### # In your test module, register test handlers again class names # ################################################################### package My::ModuleTester; use Test::More; use Test::Object; # Foo::Bar is a subclass of Foo Test::Object->register( class => 'Foo', tests => 5, code => &foo_ok, ); Test::Object->register( class => 'Foo::Bar', # No fixed number of tests code => &foobar_ok, ); sub foo_ok { my $object = shift; ok( $object->foo, '->foo returns true' ); } sub foobar_ok { my $object = shift; is( $object->foo, 'bar', '->foo returns "bar"' ); } 1; ################################################################### # In test script, test object against all registered classes # ################################################################### #!/usr/bin/perl -w use Test::More 'no_plan'; use Test::Object; use My::ModuleTester; my $object = Foo::Bar->new; isa_ok( $object, 'Foo::Bar' ); object_ok( $object ); DESCRIPTION
In situations where you have deep trees of classes, there is a common situation in which you test a module 4 or 5 subclasses down, which should follow the correct behaviour of not just the subclass, but of all the parent classes. This should be done to ensure that the implementation of a subclass has not somehow "broken" the object's behaviour in a more general sense. "Test::Object" is a testing package designed to allow you to easily test what you believe is a valid object against the expected behaviour of all of the classes in its inheritance tree in one single call. To do this, you "register" tests (in the form of CODE or function references) with "Test::Object", with each test associated with a particular class. When you call "object_ok" in your test script, "Test::Object" will check the object against all registered tests. For each class that your object responds to "$object->isa($class)" for, the appropriate testing function will be called. Doing it this way allows adapter objects and other things that respond to "isa" differently that the default to still be tested against the classes that it is advertising itself as correctly. This also means that more than one test might be "counted" for each call to "object_ok". You should account for this correctly in your expected test count. SUPPORT
Bugs should be submitted via the CPAN bug tracker, located at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Object> For other issues, contact the author. AUTHOR
Adam Kennedy <cpan@ali.as> SEE ALSO
<http://ali.as/>, Test::More, Test::Builder::Tester, Test::Class COPYRIGHT
Copyright 2005, 2006 Adam Kennedy. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of the license can be found in the LICENSE file included with this module. perl v5.16.3 2006-09-07 Test::Object(3)
All times are GMT -4. The time now is 01:43 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy