Sponsored Content
Top Forums Shell Programming and Scripting Search two patterns using awk to print the variable sum Post 302778627 by franzpizzo on Monday 11th of March 2013 10:29:35 AM
Old 03-11-2013
Set the (value of silver) in this code:
Code:
awk '
/^gold/ {gold += $2}
/^silver/ {silver += $2}
END {print "value = $" 425*gold;print "value = $" (value of silver)*silver }' coins.txt

 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

connecting search patterns in awk with AND

Hello friends, I couldnt connect two search patterns in awk, what i want is to search for two words in a log file; "+MB)" and "Done" i use this code /usr/xpg4/bin/awk '/+MB)/ {gsub("\(","",$5);print int($5)}' mylog.txt and i get integer part of (123,45MB) in a log file "mylog" with ... (1 Reply)
Discussion started by: EAGL€
1 Replies

2. Shell Programming and Scripting

Using a script variable in awk search patterns

Hi all, In a script like : job_date=.... ls -l 2>/dev/null | awk -v var =$job_date ' /Name\.Version\.+\.xml$/ { How can i include a script variable job_date store in "var" in the pattern "/Name\.Version\.+\.xml$/" Thanks in advance (12 Replies)
Discussion started by: abhinav192
12 Replies

3. Shell Programming and Scripting

loop + sum + print using awk

Hi, I am unable sum of each column in the loop usng awk command. Awk is not allowing the parameters in the command. i am facing the below error. awk: 0602-562 Field $() is not correct. Source file abc.txt 100,200,300,400,500,600,700,800,900 101,201,301,401,501,601,701,801,901 ... (1 Reply)
Discussion started by: number10
1 Replies

4. Shell Programming and Scripting

awk: Multiple search patterns & print in an one liner

I would like to print result of multiple search pattern invoked from an one liner. The code looks like this but won't work gawk -F '{{if ($0 ~ /pattern1/) pat1=$1 && if ($0 ~ /pattern2/) pat2=$2} ; print pat1, pat2}' Can anybody help getting the right code? (10 Replies)
Discussion started by: sdf
10 Replies

5. Shell Programming and Scripting

Search for the two patterns and print everything in between

Hi all, I have a file having data: @HWUSI-EAS1727:19:6:1:3674:984:0:1#GTTAATA NTTGGGTTTTCT @HWUSI-EAS1727:19:6:1:3674:984:0:1#GTTA... NTTGGGTTTTCT @HWUSI-EAS1727:19:6:1:3674:984:0:1#.....CT NTTGGGTTTTCT I want to print everything starting from # till line ends. can you please help me how... (5 Replies)
Discussion started by: pirates.genome
5 Replies

6. Shell Programming and Scripting

sum from ls -al |awk '{print $5}'

// AIX 5.3 & AIX 6.1 ls -al |awk '{print $5}' This gives each file's size in byte. I need to get: - the sum of all files in Giga bytes with loop. - excluding the size of directories (ls -al returns the size of directories). There are hundreds and thousands of files, so summing up... (8 Replies)
Discussion started by: Daniel Gate
8 Replies

7. Shell Programming and Scripting

awk search patterns from file in another

I would like to grep for aaa and bbb and ccc from one line in file1.txt in any order on a line on file2.txt file1.txt aaa bbb ccc ddd fff ggg hhh ddd jjj jjj cccfile2.txt aaa bbb ccc ddd fff ggg --> output whole line since it matches with aaa bbb ccc of file1.txt aaa ddd jjj hhh --> no... (1 Reply)
Discussion started by: sdf
1 Replies

8. Shell Programming and Scripting

awk - Print Sum

Hi, I have an awk command that I am using, and part of it sums COL_9 however when I read the output it is not including decimal places; awk ' BEGIN{FS=OFS=","} NR==1{print;next} {a+=$9 c = $12 d = $18 } END{for(i in a) {split(i,b,";"); print $1, $2, $3, b, $5, $6, b, b, a, $10, $11,... (1 Reply)
Discussion started by: Ads89
1 Replies

9. Shell Programming and Scripting

awk variable search and line count between variable-search pattern

Input: |Running the Rsync|Sun Oct 16 22:48:01 BST 2016 |End of the Rsync|Sun Oct 16 22:49:54 BST 2016 |Running the Rsync|Sun Oct 16 22:54:01 BST 2016 |End of the Rsync|Sun Oct 16 22:55:45 BST 2016 |Running the Rsync|Sun Oct 16 23:00:02 BST 2016 |End of the Rsync|Sun Oct 16 23:01:44 BST 2016... (4 Replies)
Discussion started by: busyboy
4 Replies
Net::SIP::Util(3pm)					User Contributed Perl Documentation				       Net::SIP::Util(3pm)

NAME
Net::SIP::Util - utility functions used by all of Net::SIP SYNOPSIS
use Net::SIP::Util qw( create_rtp_sockets ); my ($port,@socks) = create_rtp_sockets( '192.168.0.10' ) or die; DESCRIPTION
This package implements various utility function used within various Net::SIP packages and partly usable for the user of Net::SIP too. Each of this functions is exportable, but none is exported per default. All functions can be exported at once with the import flag ":all". SUBROUTINES
invoke_callback ( CALLBACK, @ARGS ) Invokes callback CALLBACK with additional args @ARGS. CALLBACK can be: A code reference In this case it will be called as "$CALLBACK->(@ARGS)" and return the return value of this call. A reference to a scalar In this case the scalar will be set to $ARGS[0] and the rest of @ARGS will be ignored. If no @ARGS are given the scalar will be set to TRUE. It will return with the value of the scalar. An object which has a method run In this case it will call "$CALLBACK->run(@ARGS)" and return with the return value of this call. A reference to an array The first element of the array will be interpreted as code reference, while the rest as args, e.g. it will do: my ($coderef,@cb_args) = @$CALLBACK; return $coderef->( @cb_args, @ARGS ); A regular expression In this case it will try to match all @ARGS against the regex. If anything matches it will return TRUE, else FALSE. create_socket_to ( ADDR, [ PROTO ] ) Creates socket with protocol PROTO (default 'udp') on a local interface, from where ADDR is reachable. This is done by first creating a UDP socket with target ADDR and using getsockname(2) to find out the local address of this socket. The newly created socket than will be bound to this address. It will try to bind the socket to port 5060 (default SIP port). If this fails it will try port 5062..5100 and if it cannot bind to any of these ports it will just use any port which gets assigned by the OS. For multihomed hosts where several addresses are bound to the same interface it will just use one of these addresses. If you need more control about the address the socket is bound to (and which will be used as the local IP in outgoing packets) you need to create the socket yourself. In scalar context it just returns the newly created socket. In array context it will return the socket and the "ip:port" the created socket is bound to. If the creation of the socket fails it will return "()" and set $!. Example: my ($sock,$ip_port) = create_socket_to ( '192.168.0.1' ) or die $!; create_rtp_sockets ( LADDR, [ RANGE, MINPORT, MAXPORT, TRIES ] ) This tries to allocate sockets for RTP. RTP consists usually of a data socket on an even port number and a control socket (RTCP) and the following port. It will try to create these sockets. MINPORT is the minimal port number to use (default 2000), MAXPORT the highest port (default MINPORT+10000), TRIES is the number of attempts it makes to create such socket pairs and defaults to 1000. RANGE is the number of consecutive ports it needs to allocate and defaults to 2 (e.g. data and control socket). Allocation will be done by choosing a random even number between MINPORT and MAXPORT and then trying to allocate all the sockets on this and the following port numbers. If the allocation fails after TRIES attempts were made it will return "()", otherwise it will return an array with at first the starting port number followed by all the allocated sockets. Example: my ($port,$rtp_sock,$rtcp_sock) = create_rtp_sockets( '192.168.0.10' ) or die "allocation failed"; sip_hdrval2parts ( KEY, VALUE ) Interprets VALUE as a value for the SIP header field KEY and splits it into the parts (prefix, parameter). Because for most keys the delimiter is ";", but for some keys "," the field name KEY need to be known. KEY needs to be normalized already (lower case, no abbrevation). Returns array with initial data (up to first delimiter) and the parameters as hash. Example for key 'to': '"Silver; John" <silver@example.com>; tag=...; protocol=TCP' -> ( '"Silver; John" <silver@example.com>', { tag => ..., protocol => 'TCP' } ) Example for key 'www-authenticate': 'Digest method="md5", qop="auth"' -> ( 'Digest', { method => 'md5', qop => 'auth' } ) sip_parts2hdrval ( KEY, PREFIX, \%PARAMETER ) Inverse function to sip_hdrval2parts, e.g constructs header value for KEY from PREFIX and %PARAMETER and returns value. sip_uri2parts ( URI ) Returns parts from URI. If called in scalar context it returns only the domain part. In array context it returns an array with the following values: domain - The domain part (including ports if any) user - The user part of the SIP address proto - The protocol, e.g. "sip" or "sips". data - The part before any parameter, includes SIP address param - A hash reference to any parameter, like in sip_hdrval2parts. sip_uri_eq ( URI1, URI2 ) Returns true if both URIs point to the same SIP address. This compares user part case sensitive, domain part case insensitive (does no DNS resolution) protocol and ports in domain (assumes default ports for protocol if no port is given). perl v5.14.2 2010-02-02 Net::SIP::Util(3pm)
All times are GMT -4. The time now is 02:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy