03-11-2013
Search two patterns using awk to print the variable sum
Coins.txt:
gold 1 1986 USA American Eagle
gold 1 1908 Austria-Hungary Franz Josef 100 Korona
silver 10 1981 USA ingot
gold 1 1984 Switzerland ingot
gold 1 1979 RSA Krugerrand
gold 0.5 1981 RSA Krugerrand
gold 0.1 1986 PRC Panda
silver 1 1986 USA Liberty dollar
gold 0.25 1986 USA Liberty 5-dollar piece
silver 0.5 1986 USA Liberty 50-cent piece
silver 1 1987 USA Constitution dollar
gold 0.25 1987 USA Constitution 5-dollar piece
gold 1 1988 Canada Maple Leaf
awk '/gold/ {ounces += $2} END {print "value = $" 425*ounces}' coins.txt
Output: value = $2592.5
When i tried modifying one of the above programs to calculate and display the total amount (in ounces) of gold and silver, separately but with one program. By using two pairs of pattern/action but it won’t works.
Help me on the above obligation
Last edited by Ramesh M; 03-11-2013 at 11:15 AM..
9 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
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
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
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
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
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
// 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
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
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
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
ROGUE(6) Games Manual ROGUE(6)
NAME
rogue - Exploring The Dungeons of Doom
SYNOPSIS
/usr/games/rogue [ -r ] [ save_file ] [ -s ] [ -d ]
DESCRIPTION
Rogue is a computer fantasy game with a new twist. It is crt oriented and the object of the game is to survive the attacks of various mon-
sters and get a lot of gold, rather than the puzzle solving orientation of most computer fantasy games.
To get started you really only need to know two commands. The command ? will give you a list of the available commands and the command /
will identify the things you see on the screen.
To win the game (as opposed to merely playing to beat other people's high scores) you must locate the Amulet of Yendor which is somewhere
below the 20th level of the dungeon and get it out. Nobody has achieved this yet and if somebody does, they will probably go down in his-
tory as a hero among heroes.
When the game ends, either by your death, when you quit, or if you (by some miracle) manage to win, rogue will give you a list of the top-
ten scorers. The scoring is based entirely upon how much gold you get. There is a 10% penalty for getting yourself killed.
If save_file is specified, rogue will be restored from the specified saved game file. If the -r option is used, the save game file is pre-
sumed to be the default.
The -s option will print out the list of scores.
The -d option will kill you and try to add you to the score file.
For more detailed directions, read the document A Guide to the Dungeons of Doom.
AUTHORS
Michael C. Toy, Kenneth C. R. C. Arnold, Glenn Wichman
FILES
/usr/games/lib/rogue_roll Score file
~/rogue.save Default save file
SEE ALSO
Michael C. Toy and Kenneth C. R. C. Arnold, A guide to the Dungeons of Doom
BUGS
Probably infinite (although countably infinite). However, that Ice Monsters sometimes transfix you permanently is not a bug. It's a fea-
ture.
4th Berkeley Distribution May 6, 1986 ROGUE(6)