Help with printing output format from a file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help with printing output format from a file
# 1  
RedHat 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:

Code:
 sample_type=
record
  decimal(",") test_type;
  date("DD-MM-YYYY")(",") test_date = NULL("");
  string(",") test_time = NULL("");
  decimal(",") test_duration;
  string(",") test1_band = NULL("");
  string(",") test2_band = NULL("");
  string(",") test3_band = NULL("");
  decimal(",") test_charge;
  decimal(",") test1_charge;
  decimal(",") test2_charge;
  string(",") testa_type = NULL("");
  string(",") testb_digits = NULL("");
  string(",") testc_digits = NULL("");
  string(",") test_field_A = NULL("");
  string(",") test_field_B = NULL("");
  string(",") test_field_C = NULL("");
  string(",") test_field_D = NULL("");
  string(",") test_field_E = NULL("");
  decimal(",") test_PPP;
  string(",") Test_source_cc = NULL("");
  string(",") test_field_xcv = NULL("");
  string(",") test_call = NULL("");
   decimal("\n") test_cycle;
end;

required outpout format:

Code:
test_type;test_date;test_time;test_duration;test1_band;test2_band;test3_band;test_charge;test1_charge;test2_charge;testa_type;testb_digits;testc_digits;test_field_A;test_field_B;test_field_C;test_field_D;test_field_E;test_PPP;Test_source_cc;test_field_xcv;test_call;test_cycle

last column should not have the semi colon.

Moderator's Comments:
Mod Comment Please place code tags properly


Thanks in advance,
AAHinka

Last edited by Scrutinizer; 04-16-2015 at 10:05 AM.. Reason: Moved code tags + additional CODE tags
# 2  
Try:
Code:
awk 'NF>1{s=s (s?";":x) $2; sub(/;$/,x,s)} END{print s}' file

or
Code:
awk 'NF>1{sub(/;$/,x,$2); print $2}' file | paste -sd\; -


Last edited by Scrutinizer; 04-16-2015 at 10:47 AM..
This User Gave Thanks to Scrutinizer For This Post:
# 3  
Quote:
Originally Posted by Scrutinizer
Try:
Code:
aawk 'NF>1{s=s (s?";":x) $2; sub(/;$/,x,s)} END{print s}' file

Thank you, it worked....

Code:
 
awk 'NF>1{s=s (s?";":x) $2; sub(/;$/,x,s)} END{print s}'

 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #608
Difficulty: Easy
Python does not need compilation to binary to run.
True or False?

10 More Discussions You Might Find Interesting

1. 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

2. UNIX for Dummies Questions & Answers

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. cat test_tes123.dml record string("\001") emp_num; /* CHAR(11) NOT NULL*/ date("YYYYMMDD")... (1 Reply)
Discussion started by: AAHinka
1 Replies

3. 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

4. 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

5. 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

6. 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

7. Shell Programming and Scripting

format a file to this output

hi i need some help over here.. please help i have a log file as per below --------------------------------------------------------------------------------------------------------- JOB START DATE : 20110510204513 JOB ID : us2cap3ds9... (6 Replies)
Discussion started by: sitaldip
6 Replies

8. 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

9. 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

10. Shell Programming and Scripting

format the output from a file

hi , i need to format the output which is availble in a file file output is Following are the Process_Scheduler Domains running in the server Ram-pc VPORCL Following are the Application Server domains running in the server Ram-pc VPORCL01 VPORCL02 these value VPORCL,VPORCL01...... (5 Replies)
Discussion started by: becksram123
5 Replies

Featured Tech Videos