Sponsored Content
Full Discussion: striping the text in AWK
Top Forums Shell Programming and Scripting striping the text in AWK Post 302144245 by summer_cherry on Wednesday 7th of November 2007 12:32:24 AM
Old 11-07-2007
awk

Hi Guy,
I like this one, it is really a interesting question.
Hope below can help you.

input:
Code:
A
Risk Severity: High Area: External Network Relative Rating: Medium
B
Risk Severity: High Area: External Network Relative Rating: Poor
C
Risk Severity: High Area: Administrative Relative Rating: High
D
Risk Severity: High Area: Internal Network Relative Rating: Medium
E
Risk Severity: High Area: Internal Network Relative Rating: Inadequate
F
Risk Severity: High Area: Administrative Relative Rating: Excellent

output:
Code:
C Risk Severity: 5 Area: Administrative Relative Rating: 4
F Risk Severity: 5 Area: Administrative Relative Rating: 5
Administrative Average:Risk Severity:5 ------ Relative Rating:4.5

D Risk Severity: 5 Area: Internal Network Relative Rating: 3
E Risk Severity: 5 Area: Internal Network Relative Rating: 1
Internal Average:Risk Severity:5 ------ Relative Rating:2

A Risk Severity: 5 Area: External Network Relative Rating: 3
B Risk Severity: 5 Area: External Network Relative Rating: 2
External Average:Risk Severity:5 ------ Relative Rating:2.5

code:
Code:
awk 'BEGIN{
sev["High"]=5
sev["Medium"]=3
sev["Low"]=1
rate["Inadequate"]=1
rate["Poor"]=2
rate["Medium"]=3
rate["High"]=4
rate["Excellent"]=5
}
{
if (NF>2)
{
	$3=sev[$3]
	$NF=rate[$NF]
	sum_rate[$5]=sum_rate[$5]+$NF
	sum_sev[$5]=sum_sev[$5]+$3
	num[$5]=num[$5]+1
	out[$5]=sprintf("%s\n%s %s",out[$5],temp,$0)
}
else
{
	temp=$0
}
}
END{
for(i in out)
{
	print out[i]
	print i" Average:Risk Severity:"sum_sev[i]/num[i]" ------ Relative Rating:"sum_rate[i]/num[i]
}
}' filename

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Striping process variable

Hello. I would like to strip out the process name from the ${0##*\} variable. So that if I have a script named "mytest.script" the variable would be populated with just "mytest" I have tried doing a substring but it doesnt seem to work. name=`expr match "${0}" : './*\(/*.\)'` Doing this... (4 Replies)
Discussion started by: new9021
4 Replies

2. Shell Programming and Scripting

echo is striping mah quotes

As the title says, echo is striping my quotes and I need them. echo "<?xml version="1.0" encoding="ISO-8859-1"?>" returns: <?xml version=1.0 encoding=ISO-8859-1?> Obviously, echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" returns the result I need: <?xml version="1.0"... (3 Replies)
Discussion started by: s_becker
3 Replies

3. Windows & DOS: Issues & Discussions

"Striping" the background of an Rxvt/Urxvt window in Cygwin

To get this: https://www.unix.com/members/silversleevesx-albums-incidental-shot-glass-picture127-termshot-rxvt-rootless.png out of Cygwin's rxvt, you have to tweak your /cygwin/etc/x11/app-defaults/rxvt file, which is here:... (0 Replies)
Discussion started by: SilversleevesX
0 Replies

4. Shell Programming and Scripting

using awk to format text

I'm new to awk and would appreciate a jump start. I've got a text doc of people with first and last names, ages, home cities, and a phrase about the individual. I want to parse the text into fields and rows separated by tabs with the field names of - Firstname, Lastname, Age, City, Dollar... (5 Replies)
Discussion started by: jkandel
5 Replies

5. Shell Programming and Scripting

sed - striping out html tags

I have pasted the contents of a log file (swmbackup.wrkstn.1262071383.sales2a) below: Workstation: sales2a<BR Vault sales2a-hogwarts will be initialized.<BR <font color="red"There was a problem mounting /mnt/sales2a/desktop$ </FONT<BR <font color="red"There was a problem mounting... (4 Replies)
Discussion started by: bigtonydallas
4 Replies

6. Shell Programming and Scripting

Extracting text from within a section of text using AWK

I have a command which returns the below output. How can I write a script to extract mainhost and secondhost from this output and put it into an array? I may sometimes have more hosts like thirdhost. I am redirecting this output to a variable. So I guess there should be a awk or sed command to... (7 Replies)
Discussion started by: heykiran
7 Replies

7. Shell Programming and Scripting

Difference between /text/ and "text" in awk

Why does this search give different result in awk I do see a mix of this in the example around the net. What to use and why? data 1 = red 2 = green 3 = blue 4 = black awk '$3 == /blue/' data "no result" awk '$3 == "blue"' data 3 = blue awk '$3 ~ /blue/' data 3 = blue (9 Replies)
Discussion started by: Jotne
9 Replies

8. Shell Programming and Scripting

Text processing using awk

I dispose of two tab-delimited files (the first column is the primary key): File 1 (there are multiple rows sharing the same key, I cannot merge them) A 28,29,30,31 A 17,18,19 B 11,13,14,15 B 8,9File 2 (there is one only row beginning with a given key) A 2,8,18,30,31 B ... (3 Replies)
Discussion started by: dovah
3 Replies

9. Shell Programming and Scripting

awk to skip lines find text and add text based on number

I am trying to use awk skip each line with a ## or # and check each line after for STB= and if that value in greater than or = to 0.8, then at the end of line the text "STRAND BIAS" is written in else "GOOD". So in the file of 4 entries attached. awk tried: awk NR > "##"' "#" -F"STB="... (6 Replies)
Discussion started by: cmccabe
6 Replies

10. Shell Programming and Scripting

awk - help in removing some text

Hey Guys, Earlier I asked a question under Solaris, which I got great help... thanks. Although I got the script working for what it really needed to do, I am looking for a bit of help to change the output for nicer reading. my script gets a list of zones under a global-zone and puts this... (4 Replies)
Discussion started by: dakelly
4 Replies
GLARENDX(1)						      General Commands Manual						       GLARENDX(1)

NAME
glarendx - calculate glare index SYNOPSIS
glarendx -t type [ -h ] [ glarefile ] DESCRIPTION
Glarendx computes the selected glare index type from the given glarefile produced by findglare(1). Glarendx computes one value for each (indirect illuminance) angle in the input file. If no glarefile is given, glarendx reads from the standard input. The -h option can be used to remove the information header from the output. Glarendx understands the following arguments for type: guth_vcp Guth Visual Comfort Probability cie_cgi CIE Glare Index (Einhorn) ugr Unified Glare Rating brs_gi BRS Glare Index dgi Daylight Glare Index guth_dgr Guth Disability Glare Rating vert_dir Direct Vertical Illuminance vert_ill Total Vertical Illuminance vert_ind Indirect Vertical Illuminance Alternatively, a symbolic or hard link to the program with any of the above names may be used in place of the type argument. AUTHORS
Greg Ward, Raphael Compagnon ACKNOWLEDGEMENT
Work on this program was initiated and sponsored by the LESO group at EPFL in Switzerland. SEE ALSO
findglare(1), glare(1), igraph(1), rpict(1), xglaresrc(1), ximage(1) RADIANCE
3/24/94 GLARENDX(1)
All times are GMT -4. The time now is 12:55 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy