Help with printing advance output format from a file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help with printing advance output format from a file
# 1  
Old 04-20-2015
Help with printing advance output format from a file

Hi,


below 'awk' code was given for my thread 'Help with printing output format from a file ' earlier, however script is not resulting expected output with below file content.


Code:
 
cat test_tes123.dml
 
record
  string("\001") emp_num; /* CHAR(11) NOT NULL*/
  date("YYYYMMDD") start_date = NULL; /* DATE NOT NULL*/
  date("YYYYMMDD") end_date = NULL; /* DATE NOT NULL*/
  string(1) status = NULL; /* CHAR(1) NOT NULL*/
  string(1) flag = NULL; /* CHAR(1)*/
  decimal("\001", maximum_length=12) unit_number = NULL; /* VARCHAR2(9)*/
  string("\001", maximum_length=9) Sal= NULL; /* VARCHAR2(9) NOT NULL*/
  string("\001", maximum_length=11) manager = NULL; /* VARCHAR2(11)*/
  decimal("\001", maximum_length=12) d_no  = NULL;
end;

 
-------
 
awk 'NF>1{s=s (s?";":x) $2; sub(/;$/,x,s)} END{print s}' test_tes123.dml
 
emp_num;start_date;end_date;status;flag;maximum_length=12);maximum_length=9);maximum_length=11);maximum_length=12)

 
---Where expected output is:
 
emp_num;start_date;end_date;status;flag;unit_number;Sal;manager;d_no

Could you please suggest solution for above query.

Thanks in advance,
AA HINKA
# 2  
Old 04-20-2015
Try
Code:
awk     '
                        {gsub (/\([^)]*\)|;.*$/,"")}

/record|end$/           {next}
                        {X=$NF}
match($0, /[^ ]* *=/)   {X=substr ($0, RSTART, RLENGTH)}

                        {sub (/ *=$/,"", X)
                         printf "%s%s", DEL, X
                         DEL=";"
                        }
END                     {print _}

' file

but be aware that your files not strictly adhering to a definite structure can't be parsed very easily.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Printing df -h output in json format

Hi All, i am trying to print the df -h ouput in json format. using below script. #!/usr/bin/env bash df -h > /tmp/sdf nawk '{print " "$1" "$2" "$3" "$4" "$5" "$6" "}' /tmp/sdf > /tmp/sdf1 nawk 'NR==1 { for (i=1; i<=NF; i++) { f = i }}{ print $(f), $(f), $(f), $(f), ... (2 Replies)
Discussion started by: sravani25
2 Replies

2. Shell Programming and Scripting

Printing Terminal Output to a Error File

I am having a bash script which is basically invoking a python program to validate the Source Query results against the target query results. I am placing all the queries in a .sql file. I want to write to a Error log file incase if the syntax is wrong or if the column is not present in the... (4 Replies)
Discussion started by: ronitreddy
4 Replies

3. UNIX for Dummies Questions & Answers

Help with printing output format from a file

Hi, I need help in printing data in below format from file extensions with .dml, i have listed details below file name is test_temp.dml, location in /home/users/test01/test_temp.dml file content: sample_type= record decimal(",") test_type; date("DD-MM-YYYY")(",") test_date... (2 Replies)
Discussion started by: AAHinka
2 Replies

4. Shell Programming and Scripting

Script to generate Excel file or to SQL output data to Excel format/tabular format

Hi , i am generating some data by firing sql query with connecting to the database by my solaris box. The below one should be the header line of my excel ,here its coming in separate row. TO_CHAR(C. CURR_EMP_NO ---------- --------------- LST_NM... (6 Replies)
Discussion started by: dani1234
6 Replies

5. Shell Programming and Scripting

Recursive file processing from a path and printing output in a file

Hi All, The script below read the path and searches for the directories/subdirectories and for the files. If files are found in the sub directories then read the content of the all files and put the content in csv(comma delimted) format and the call the write to xml function to write the std... (1 Reply)
Discussion started by: Optimus81
1 Replies

6. Shell Programming and Scripting

Match list of strings in File A and compare with File B, C and write to a output file in CSV format

Hi Friends, I'm a great fan of this forum... it has helped me tone my skills in shell scripting. I have a challenge here, which I'm sure you guys would help me in achieving... File A has a list of job ids and I need to compare this with the File B (*.log) and File C (extend *.log) and copy... (6 Replies)
Discussion started by: asnandhakumar
6 Replies

7. Shell Programming and Scripting

Printing the output of a db2 query on to an unix file

I want to print the output of a db2 query, on to an unix file in a manner that the columns are separated by 'commas'. Please help me out..thanx in advance (1 Reply)
Discussion started by: prasan_ven
1 Replies

8. Shell Programming and Scripting

Advance file parsing...

hi all i have a file of the format Time(starting from 0 in asc order) bytes service flags protocols e.g. 0, 0, 0, 56, 56 1, 524, 3, 6, 75 1, 624, 0, 43, 53 2, 72, 0, 43, 80 3, ... (1 Reply)
Discussion started by: vaibhavkorde
1 Replies

9. Shell Programming and Scripting

Dynamic output file generation using a input text file with predefined output format

Hi, I have two files , one file with data file with attributes that need to be sent to another file to generate a predefined format. Example: File.txt AP|{SSHA}VEEg42CNCghUnGhCVg== APVG3|{SSHA}XK|"password" AP3|{SSHA}XK|"This is test" .... etc --------- test.sh has... (1 Reply)
Discussion started by: hudson03051nh
1 Replies

10. Shell Programming and Scripting

Shell programming - running the exe file and printing the output.. ?

hai i have a directory lib in that lib directory i have 10 batch files. step i have to do is 1) EXECUTE ALL THE FILES by using the command dwarfdump <filename>| grep DW_AT_SUN_command_line and put the output in one text file.instead of executing the files for all the 10 files... (13 Replies)
Discussion started by: shenthil76
13 Replies
Login or Register to Ask a Question