Sponsored Content
Top Forums Shell Programming and Scripting awk operation to get table formatted file Post 302965994 by Don Cragun on Friday 5th of February 2016 07:16:11 PM
Old 02-05-2016
Making some wild guesses about an input file that produces the intermediate files you said you wanted, and writing a simple awk script that goes straight from the input file to the output you said you wanted (without creating intermediate files), you might want to try something like:
Code:
awk '
BEGIN {	FS = "[] ,-]"
	OFS = "\t"
	print "Extension", "int_mail", "ext_mail"
	OFS = OFS OFS
}
function ext_print() {
	if(e)	print e, f["int"], f["ext"]
	e = $2
	f["ext"] = f["int"] = "null"
}
/^[[]sub_suffix/ {
	ext_print()
	next
}
/mdc_template/ {
	f[$3] = "yes"
}
END {	ext_print()
}' file

If the file named file contains:
Code:
[sub_suffix-324]
; generated by mod_identity
exten => int,1,GoSub(mdc_template-3,s,1)
exten => int,n(next_380),Return()
; default action for busy
exten => ext,1,GoSub(mdc_template-3,s,1)
exten => ext,n,Set(PRI_CAUSE=17)
exten => ext,n,HangUp(17)
exten => ext,n(back),Return()
[sub_suffix-424]
; generated by mod_identity
exten => int,1,GoSub(mdc_template-3,s,1)
exten => int,n(next_380),Return()
; default action for busy
exten => ext,1,GoSub(mdc_template-3,s,1)
exten => ext,n,Set(PRI_CAUSE=17)
exten => ext,n,HangUp(17)
exten => ext,n(back),Return()
[sub_suffix-321]
; generated by mod_identity
exten => int,1,GoSub(mdc_template-3,s,1)
exten => int,n(next_380),Return()
; default action for busy
exten => ext,n,Set(PRI_CAUSE=17)
exten => ext,n,HangUp(17)
exten => ext,n(back),Return()
[sub_suffix-3245]
; generated by mod_identity
exten => int,n(next_380),Return()
; default action for busy
exten => ext,1,GoSub(mdc_template-3,s,1)
exten => ext,n,Set(PRI_CAUSE=17)
exten => ext,n,HangUp(17)
exten => ext,n(back),Return()
[sub_suffix-7435]
; generated by mod_identity
exten => int,n(next_380),Return()
; default action for busy
exten => ext,n,Set(PRI_CAUSE=17)
exten => ext,n,HangUp(17)
exten => ext,n(back),Return()
[sub_suffix-123]
; generated by mod_identity
exten => int,n(next_380),Return()
; default action for busy
exten => ext,n,Set(PRI_CAUSE=17)
exten => ext,n,HangUp(17)
exten => ext,n(back),Return()
[sub_suffix-325]
; generated by mod_identity
exten => int,1,GoSub(mdc_template-3,s,1)
exten => int,n(next_380),Return()
; default action for busy
exten => ext,1,GoSub(mdc_template-3,s,1)
exten => ext,n,Set(PRI_CAUSE=17)
exten => ext,n,HangUp(17)
eaten => ext,n(back),Return()

it produces the output:
Code:
Extension	int_mail	ext_mail
324		yes		yes
424		yes		yes
321		yes		null
3245		null		yes
7435		null		null
123		null		null
325		yes		yes

If you want to try this on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awik or nawk.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk - print formatted without knowing no of cols

Hi, i want to print(f) the content of a file, but i don't know how many columns it has (i.e. it changes from each time my script is run). The number of columns is constant throughout the file. Any suggestions? (8 Replies)
Discussion started by: bistru
8 Replies

2. Shell Programming and Scripting

Formatted output - awk

Hi I have the following records in a file SABN YOURTUBE 000514 7256 SACN XYOUDSDF 000514 7356 SADN KEHLHRSER 000514 7656 SAEN YOURTUBE 000514 7156 SAFN YOURTUBE 000514 7056 I need to put this in the format like this printf '%s %-50s %6s %-6s\n' I am not going to read individual... (3 Replies)
Discussion started by: dhanamurthy
3 Replies

3. UNIX for Dummies Questions & Answers

Problem with formatted printing in AWK

Hi, I want to print 130 fileds using formatted printing in AWK. It looks like awk '{printf ("%7.2f%7.2f...%7.2\n",$1,$2,...,$130)}' inflie>oufile But it gives me an error: Word too long! Can you please help me with this? Is there another way to do this? (1 Reply)
Discussion started by: PHL
1 Replies

4. Shell Programming and Scripting

output - tab formatted - awk

Dear All, Good Day. I would like to hear your suggestions for the following problem: I have a file with 5 columns with some numbers in 16 lines as shown below. Input file: Col 1 Col 2 Col 3 Col 4 Col 5 12 220 2 121 20 234 30 22 9... (3 Replies)
Discussion started by: Fredrick
3 Replies

5. Shell Programming and Scripting

awk, sed, perl assistance in outputting formatted file

Hello, Please advise. Scoured this site, as well as google for answers. However if you do not know what to search for, it's a bit hard to find answers. INPUT: ACTASS= 802 BASECOS= 279 COSNCHG= 3 CUSCOS= 52 UPLDCOS= 2 DESIRED OUTPUT: ACTASS=802 BASECOS=279 (13 Replies)
Discussion started by: abacus
13 Replies

6. Shell Programming and Scripting

awk to convert table-by-row to matrix table

Hello, I need some help to reformat this table-by-row to matrix? infile: site1 A:o,p,q,r,s,t site1 C:y,u site1 T:v,w site1 -:x,z site2 A:p,r,t,v,w,z site2 C:u,y site2 G:q,s site2 -:o,x site3 A:o,q,s,t,u,z site3 C:y site3 T:v,w,x site3 -:p,routfile: SITE o p q r s t v u w x y... (7 Replies)
Discussion started by: yifangt
7 Replies

7. Shell Programming and Scripting

awk --> math-operation in data-record and joining with second file data

Hi! I have a pretty complex job - at least for me! i have two csv-files with meassurement-data: fileA ...... (2 Replies)
Discussion started by: IMPe
2 Replies

8. Shell Programming and Scripting

Multiple Replacement in a Text File in one operation (sed/awk) ?

Hi all, Saying we have two files: 1. A "Reference File" whose content is "Variable Name": "Variable Value" 2. A "Model File" whose content is a model program in which I want to substitute "VariableName" with their respective value to produce a third file "Program File" which would be a... (4 Replies)
Discussion started by: dae
4 Replies

9. Shell Programming and Scripting

awk script to find data in three file and perform replace operation

Have three files. Any other approach with regards to file concatenation or splitting, etc is appreciated If column55(billngtype) of file1 contains YMNC or YPBC then pick the value of column13(documentnumber). Now find this documentnumber in column1(Billdoc) of file2 and grep the corresponding... (4 Replies)
Discussion started by: as7951
4 Replies

10. Shell Programming and Scripting

Processing a formatted file with awk

Hi - I want to interrogate information about my poker hands, sessions are all recorded in a text file in a particular format. Each hand starts with the string <PokerStars> followed by a unique hand reference and other data like date/time. There is then all the information about each hand. My first... (5 Replies)
Discussion started by: rbeech23
5 Replies
All times are GMT -4. The time now is 08:43 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy