Awk: How to get an awk variable out to the shell, using system() ?
I am reasonably capable with awk and its quirks, but not with shell weirdness. This has to be Bourne Shell for portability reasons. I have an awk program that is working just fine; it handles multiple input streams and produces several reports, based on the request (-v Variables). In addition to processing the stream, and producing the required report in the stream (so that it can be re-directed, etc), I write certain errors to a separate file.
Now I need to enhance the program, to write to a specific filename (constructed per execution, no problem), and to sort the contents.
I used the Site Search but nothing similar came up, due to the hundreds of badly formed thread titles.
The generic question may be as simple as the thread title.
This code snippet contains the seed of the problem, in simple form. The last two lines of code is a statement of intent; obviously it does not work as is.
Alternate approaches are welcome, as long as it does not result in a major code change.
I wanna use a system function to deal with several data. So I use awk variable FILENAME to transfer the file directory to system command, but it does not work.
I use a shell function "out_function" to deal with data and save the result in another directory with the same file name.
How can I... (2 Replies)
Hi All,
How can i use the file for printing in awk
file1
----------
update table crn_ras_disc_dtl a set a.a5=$1,a.a1=$2,a.a2=$3,a.a3=$4,a.a4=$5;
file2
--------
10|KUMAR|23|MALE|US
20|RAJ|24|MALE|AU
Output
---------
update table crn_ras_disc_dtl a set... (12 Replies)
line_no=6
echo 'Phone,' `awk 'NR==$line_no{print;exit}' <filename>`
what is the error in this..
it says..
awk: Field $() is not correct.
The input line number is 1. The file is <filename>.
The source line number is 1.
i want to print the data in the $line_no line of a certain... (2 Replies)
Hi all,
I am calling a shell function within awk using system. I am struggling to get my expected output:
#!/bin/sh
set -o nounset
BEG=44
END=55
shfun()
{
echo "1|2|3"
}
export -f shfun
typeset -F > /dev/null
awk 'BEGIN {OFS="|"; print "'"$BEG"'",system( "shfun"... (5 Replies)
Dear All,
we have a command output which looks like :
Total 200 queues in 30000 Kbytes
and we're going to get "200" and "30000" for further process. currently, i'm using :
numA=echo $OUTPUT | awk '{print $2}'
numB=echo $OUTPUT | awk '{print $5}'
my question is : can I use just one... (4 Replies)
I have 3 files and each contain m*n matrix.
m = number of rows (horizontal lines)
n = number of columns (entries in a particular line)
What I wish to find is the sum of the 2nd number in the last row.
Ex
file1.dat
2 5 8 8
4 6 7 8
3 8 3 7
file2.dat
3 4 1 4
8 4 0 3
4 7 3 7
... (3 Replies)
Hi all,
Hope someone can help me out here.
I have this BASH script (see below)
My problem lies with the variable path.
The output of the command find will give me several fields. The 9th field is the path. I want to captured that and the I want to filter this to a specific level.
The... (6 Replies)
How do you use a shell variable in awk? I am using Solaris 10 and don't have GNU products installed.
File (transportation.txt) contents:
car
boat
airplane
snowmobile
bicycle
sled
This awk statment works (prints from the car line down to bicycle
awk '/car/,/bicycle/'... (8 Replies)
Hi Experts,
I am trying to get system output to capture inside awk , but not working:
Please advise if this is possible :
I am trying something like this but not working, the output is coming wrong:
echo "" | awk '{d=system ("date") ; print "Current date is:" , d }'
Thanks, (5 Replies)
I have the following script, and I want to assign the output ($10 and $5) from awk to N and L:
grdinfo data.grd | awk '{print $10,$5}'| read N L
output from gridinfo data.grd is: data.grd 50 100 41 82 -2796 6944 0.016 0.016 3001 2461. where N and L is suppose to be 3001 and 100. I use... (8 Replies)
Perl::Critic::Policy::Modules::RequireFilenameMatchesPacUser(Contributed Perl DocumPerl::Critic::Policy::Modules::RequireFilenameMatchesPackage(3)NAME
Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage - Package declaration must match filename.
AFFILIATION
This Policy is part of the core Perl::Critic distribution.
DESCRIPTION
The package declaration should always match the name of the file that contains it. For example, "package Foo::Bar;" should be in a file
called "Bar.pm". This makes it easier for developers to figure out which file a symbol comes from when they see it in your code. For
instance, when you see "Foo::Bar->new()", you should be able to find the class definition for a "Foo::Bar" in a file called Bar.pm
Therefore, this Policy requires the last component of the first package name declared in the file to match the physical filename. Or if
"#line" directives are used, then it must match the logical filename defined by the prevailing "#line" directive at the point of the
package declaration. Here are some examples:
# Any of the following in file "Foo/Bar/Baz.pm":
package Foo::Bar::Baz; # ok
package Baz; # ok
package Nuts; # not ok (doesn't match physical filename)
# using #line directives in file "Foo/Bar/Baz.pm":
#line 1 Nuts.pm
package Nuts; # ok
package Baz; # not ok (contradicts #line directive)
If the file is not deemed to be a module, then this Policy does not apply. Also, if the first package namespace found in the file is
"main" then this Policy does not apply.
CONFIGURATION
This Policy is not configurable except for the standard options.
AUTHOR
Chris Dolan <cdolan@cpan.org>
COPYRIGHT
Copyright (c) 2006-2011 Chris Dolan.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
perl v5.16.3 2014-06-09 Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage(3)