how to parse this file and obtain a .csv or .xls


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to parse this file and obtain a .csv or .xls
# 8  
Old 04-01-2011
Just make a try with awk instead of nawk (the syntax is similar).

Code:
sed 's/^  *//;s/  */ /g;s/  *$//' infile | awk '/HELPTEXT/{x=$0;getline;do{x=x" "$0;getline}while($0!~/HELP /);sub(/ ["]OPS/,", \"OPS,",x);print x}NF>1{sub($1,$1",",$0)}1'

---------- Post updated at 04:04 PM ---------- Previous update was at 04:02 PM ----------

Code:
$ sed 's/^  *//;s/  */ /g;s/  *$//' tst | nawk '/HELPTEXT/{x=$0;getline;do{x=x" "$0;getline}while($0!~/HELP /);sub(/ ["]OPS/,", \"OPS,",x);print x}NF>1{sub($1,$1",",$0)}1'
SYNTAX_VERSION, 5

MONITOR, "NAME_TEMPLATES"
DESCRIPTION, "Monitors for contents of error "
INTERVAL, "1m"
MONPROG, "script.sh NAME_TEMPLATES"
MAXTHRESHOLD
GEN_BELOW_RESET
SEVERITY, Major
APPLICATION, "script.sh"
MSGGRP, "MSG"
MSGCONDITIONS
DESCRIPTION, "Has NEW errors"
CONDITION_ID, "00000-34dc-25e0-1cfe-0a088b060000"
CONDITION
OBJECT, "<#>diff<*.folder>"
THRESHOLD, 0.500000
RESET, 0.500000
SET
OBJECT, "<$OPTION(area)>"
TEXT, "There have been new failures Processing the <$OPTION(area)>
file, on Central.
AUTOACTION, "ls <folder>" ANNOTATE
HELPTEXT, "OPS, ========= Please call support team"
HELP, "0d152f3c-59dc-71e0-1cfe-0a034b060000"
DESCRIPTION, "Has ANY errors"
CONDITION_ID, "d26dda06-55f2-71e0-0025-0a034b060000"
CONDITION
OBJECT, "<*.folder>"
THRESHOLD, 0.500000
RESET, 0.500000
SET
OBJECT, "<$OPTION(area)>"
TEXT, "There has been a failure Processing the <$OPTION(area)> file
HELPTEXT, "OPS, ========= Please call out the support team" others instruction others instruction
HELP, "0d152f3c-59dc-71e0-1cfe-0a034b060000"
$


Last edited by ctsgnb; 04-01-2011 at 11:46 AM..
# 9  
Old 04-01-2011
Thanks your code does what I want!

Only there is a little issue, the prompt remain in hung at the end of the execution of your command, I need to stop it with CTRL+C (not good to use it in automatic script as it is my intention).

Any help?

Regards,

Ant-one
# 10  
Old 04-01-2011
Please make sure you did no typo error (don't forget any simple nor double quote).

1) Which OS/shell do you run ?

2) Please copy/paste the exact command you ran ?
# 11  
Old 04-01-2011
Hi,
1) /usr/bin/sh HP-UX 11.31

2)

Quote:
sed 's/^ *//;s/ */ /g;s/ *$//' monitor | awk '/HELPTEXT/{x=$0;getline;do{x=x" "$0;getline}while($0!~/HELP /);sub(/ ["]OPS/,", \"OPS,",x);print x}NF>1{sub($1,$1",",$0)}1'
Regards,
Ant-one
# 12  
Old 04-01-2011
(I ran it both on a linux & solaris and both worked fine and i had no such issue)

Code:
# sed 's/^  *//;s/  */ /g;s/  *$//' yourfile | awk '/HELPTEXT/{x=$0;getline;while($0!~/HELP /){x=x" "$0;getline};sub(/ ["]OPS/,", \"OPS,",x);print x}NF>1{sub($1,$1",",$0)}1'
SYNTAX_VERSION, 5

MONITOR, "NAME_TEMPLATES"
DESCRIPTION, "Monitors for contents of error "
INTERVAL, "1m"
MONPROG, "script.sh NAME_TEMPLATES"
MAXTHRESHOLD
GEN_BELOW_RESET
SEVERITY, Major
APPLICATION, "script.sh"
MSGGRP, "MSG"
MSGCONDITIONS
DESCRIPTION, "Has NEW errors"
CONDITION_ID, "00000-34dc-25e0-1cfe-0a088b060000"
CONDITION
OBJECT, "<#>diff<*.folder>"
THRESHOLD, 0.500000
RESET, 0.500000
SET
OBJECT, "<$OPTION(area)>"
TEXT, "There have been new failures Processing the <$OPTION(area)>
file, on Central.
AUTOACTION, "ls <folder>" ANNOTATE
HELPTEXT, "OPS, ========= Please call support team"
HELP, "0d152f3c-59dc-71e0-1cfe-0a034b060000"
DESCRIPTION, "Has ANY errors"
CONDITION_ID, "d26dda06-55f2-71e0-0025-0a034b060000"
CONDITION
OBJECT, "<*.folder>"
THRESHOLD, 0.500000
RESET, 0.500000
SET
OBJECT, "<$OPTION(area)>"
TEXT, "There has been a failure Processing the <$OPTION(area)> file
HELPTEXT, "OPS, ========= Please call out the support team" others instruction others instruction
HELP, "0d152f3c-59dc-71e0-1cfe-0a034b060000"

---------- Post updated at 04:44 PM ---------- Previous update was at 04:41 PM ----------

Watch out for the number of space in the sed statement !

---------- Post updated at 04:47 PM ---------- Previous update was at 04:44 PM ----------

Code:
sed 's/^  *//;s/  */ /g;s/  *$//' monitor

The wildcard is preceeded by 2 space every time
<space><space>*


(if it is not the case, it is an error : you should fix it )

Last edited by ctsgnb; 04-05-2011 at 12:08 PM..
# 13  
Old 04-01-2011
hello,
i have tried split the command in two part:

-when I use the sed statement only without the awk it works fine and I get back the prompt.
Quote:
sed 's/^ *//;s/ */ /g;s/ *$//' myfile > myfile2
hen I use the awk part it hungs:

Quote:
awk '/HELPTEXT/{x=$0;getline; while($0!~/HELP /){x=x" "$0;getline};sub(/ ["]OPS/,", \"OPS,",x);print x}NF>1{sub($1,$1",",$0)}1' myfile2
Instead if I use this command

Quote:
sed 's/^ *//;s/ */ /g;s/ *$//' myfile| awk '/HELPTEXT/{x=$0;getline;do{x=x" "$0;getline}while($0!~/HELP /);sub(/ ["]OPS/,", \"OPS,",x);print x}NF>1{sub($1,$1",",$0)}1'
I get the following output without hung:

Quote:
S, Y N T A X _ V E R S I O N 5

M, O N I T O R " N A M E _ T E M P L A T E S "
D, E S C R I P T I O N " M o n i t o r s f o r c o n t e n t s o f e r r o r "
I, N T E R V A L " 1 m "
M, O N P R O G " s c r i p t . s h N A M E _ T E M P L A T E S "
M, A X T H R E S H O L D
G, E N _ B E L O W _ R E S E T
S, E V E R I T Y M a j o r
A, P P L I C A T I O N " s c r i p t . s h "
M, S G G R P " M S G "
M, S G C O N D I T I O N S
D, E S C R I P T I O N " H a s N E W e r r o r s "
C, O N D I T I O N _ I D " 0 0 0 0 0 - 3 4 d c - 2 5 e 0 - 1 c f e - 0 a 0 8 8 b 0 6 0 0 0 0 "
C, O N D I T I O N
O, B J E C T " < # > d i f f < * . f o l d e r > "
T, H R E S H O L D 0 . 5 0 0 0 0 0
R, E S E T 0 . 5 0 0 0 0 0
S, E T
O, B J E C T " < $ O P T I O N ( a r e a ) > "
T, E X T " T h e r e h a v e b e e n n e w f a i l u r e s P r o c e s s i n g t h e < $ O P T I O N ( a r e a ) >
f, i l e o n C e n t r a l . "
A, U T O A C T I O N " l s < f o l d e r > " A N N O T A T E
H, E L P T E X T " O P S
=, = = = = = = = =
P, l e a s e c a l l s u p p o r t t e a m "
H, E L P " 0 d 1 5 2 f 3 c - 5 9 d c - 7 1 e 0 - 1 c f e - 0 a 0 3 4 b 0 6 0 0 0 0 "
D, E S C R I P T I O N " H a s A N Y e r r o r s "
C, O N D I T I O N _ I D " d 2 6 d d a 0 6 - 5 5 f 2 - 7 1 e 0 - 0 0 2 5 - 0 a 0 3 4 b 0 6 0 0 0 0 "
C, O N D I T I O N
O, B J E C T " < * . f o l d e r > "
T, H R E S H O L D 0 . 5 0 0 0 0 0
R, E S E T 0 . 5 0 0 0 0 0
S, E T
O, B J E C T " < $ O P T I O N ( a r e a ) > "
T, E X T " T h e r e h a s b e e n a f a i l u r e P r o c e s s i n g t h e < $ O P T I O N ( a r e a ) > f i l e
H, E L P T E X T " O P S
=, = = = = = = = =
P, l e a s e c a l l o u t t h e s u p p o r t t e a m "
o, t h e r s i n s t r u c t i o n
o, t h e r s i n s t r u c t i o n
Smilie
# 14  
Old 04-01-2011
could you show me what gives :
Code:
head myfile2

??

As stated in my previous post : your sed statement is WRONG :

You must put 2 space before every * in the sed statement (i put them in [ ] so you can see where they are and how many of them should be ):

Code:
sed 's/^[ ][ ]*//;s/[ ][ ]*$//;s/[ ][ ]/[ ]/g' infile

---------- Post updated at 06:07 PM ---------- Previous update was at 05:54 PM ----------

Look the difference if one space is missing, the output is messed up :

Code:
# sed 's/^ *//;s/ */ /g;s/ *$//' tst | head -3
 S Y N T A X _ V E R S I O N 5

 M O N I T O R " N A M E _ T E M P L A T E S "
# sed 's/^ *//;s/  */ /g;s/ *$//' tst | head -3
SYNTAX_VERSION 5

MONITOR "NAME_TEMPLATES"
#

But to make the code more secure, this missing space should also be added before the other * :

Code:
# sed 's/^  *//;s/  */ /g;s/  *$//' tst | head -3
SYNTAX_VERSION 5

MONITOR "NAME_TEMPLATES"


Last edited by ctsgnb; 04-01-2011 at 01:05 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Generate .csv/ xls file report

There can be thousand of .ksh in a specific directory where sql files are called from ksh. Requirement is to loop through all the files content and generate a report like below: Jobname Type type sqlname gemd1970 sql daily tran01 gemw1971 sql weekly ... (6 Replies)
Discussion started by: vedanta
6 Replies

2. Shell Programming and Scripting

Perl script to Convert XLSX or XLS files to CSV file

Hi All, I've got in a situation where I need to convert .xlsx or .xls formatted files into simple text file or .csv file. I've found many options but doing this using PERL script is the best way I believe.I'm in AIX box. Perl code should have 2 params while running. i.e perl... (1 Reply)
Discussion started by: manab86
1 Replies

3. Shell Programming and Scripting

How to convert a xls file to csv?

Hi, My requirement is to convert the xls to csv file with utf-8 conversion. Is there any way please suggest me. Thanks, Raja (4 Replies)
Discussion started by: cnraja
4 Replies

4. UNIX for Advanced & Expert Users

Converting .csv file into .xls file and send it to inbox

Hi All, I wrote a script to extract data from Oracle DB and place it in a text file , and I have coverted .txt file into comma seperated .csv file and I sent it to my mail box . I can get .xls file in my inbox.I am getting all data in same column and in different rows , without column... (1 Reply)
Discussion started by: krthkmuthu
1 Replies

5. Shell Programming and Scripting

converting xls file to txt file and xls to csv

I need to convert an excel file into a text file and an excel file into a CSV file.. any code to do that is appreciated thanks (6 Replies)
Discussion started by: bandar007
6 Replies

6. UNIX for Dummies Questions & Answers

Unix script to convert .csv file to.xls format

I have a .csv file in Unix box i need a UNIX script to convert the.csv files to.xls format. Its very urgent please help me. (1 Reply)
Discussion started by: moon_friend
1 Replies

7. Shell Programming and Scripting

Convert a csv file to an xls format

Hi, I have a file coming in xxx.txt(csv format) i do some work on it and i need to send out as a .xls format. Is there any way there is some code i can use in my script to convert this? I'm struggling on this. Thanks (11 Replies)
Discussion started by: Pablo_beezo
11 Replies

8. UNIX for Advanced & Expert Users

obtain duplicate keys in csv file

Hi, having two csv files, both sorted, by key (column1), f1 containing duplicate keys and f2 containing no duplicate keys, how can I obtain all rows from f1 with the keys listed in file2? Example: f1 is: k1,gsj01fd k2,vi982cj k2,1fjk01e k3,81kjfds k4,sd9dasi f2 is: k2 k3 and I... (3 Replies)
Discussion started by: oscarmon
3 Replies

9. Shell Programming and Scripting

From xls to csv file

Can we convert an xls file into csv format in Unix Thanks Suresh (1 Reply)
Discussion started by: sureshg_sampat
1 Replies

10. Shell Programming and Scripting

copying the csv file into different worksheets of xls file

Hi, I have a script which will generate three csv files. i want to copy the contents of these csv files into a .XLS file but in different worksheets. Can a this be done in the same script? :confused: Can Perl come to my help in coping the csv files into different worksheets of .XLS file ?... (0 Replies)
Discussion started by: nimish
0 Replies
Login or Register to Ask a Question