Printing files in a specific format


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Printing files in a specific format
# 1  
Old 04-30-2015
Printing files in a specific format

Hi,

I have following files in a directory with '.meta' extension, which have data in follwoing patterns. i need to print data from these files in below metioned format. please provide a script for this solution.

Code:
file names:
 
TEST_HISTORY_MTH.meta
AB_TEST_1.meta
 
cat TEST_HISTORY_MTH.meta
 
                   Table "TEST_HISTORY_MTH"
           Attribute           |     Type      | Modifier | Default Value
-------------------------------+---------------+----------+---------------
 MONTH_ID                      | NUMERIC(6,0)  | NOT NULL |
 ROLE_ID                       | NUMERIC(12,0) | NOT NULL |
 OUTCOME_ID                    | NUMERIC(12,0) | NOT NULL |
 REASON_ID                     | NUMERIC(12,0) | NOT NULL |
 USED_ID                       | NUMERIC(12,0) | NOT NULL |
 TEST_ID                       | NUMERIC(12,0) | NOT NULL |
 CONTACTS                      | NUMERIC(12,0) | NOT NULL |
 OFFER                         | NUMERIC(12,0) | NOT NULL |
 TIME                          | NUMERIC(12,0) | NOT NULL |
 SEQUENCE1                     | NUMERIC(12,0) | NOT NULL |
Constraints:
Name                             Settings
TEST_HISTORY_MTH_PK              Primary key(MONTH_ID,ROLE_ID,OUTCOME_ID,REASON_ID,USED_ID,TEST_ID,CONTACTS,OFFER)
Distributed on random: (round-robin)
 
 
cat AB_TEST_1.meta
 
 
                  Table "AB_TEST_1"
 Attribute |     Type      | Modifier | Default Value
-----------+---------------+----------+---------------
 NAME      | CHARACTER(10) |          |
 EMPNO     | CHARACTER(3)  |          |
 AGE       | NUMERIC(3,0)  |          |
Distributed on hash: "NAME"
 
 
Desired output for each file should be as follows (columns seperated with only one space each):
 
TEST_HISTORY_MTH MONTH_ID ROLE_ID OUTCOME_ID REASON_ID USED_ID TEST_ID CONTACTSOFFER TIME SEQUENCE1
AB_TEST_1 NAME EMPNO AGE

Regards,
AAHinka
# 2  
Old 04-30-2015
Hi,
with gnu sed (not simplified):
Code:
sed -sne '/^ *Table "/{s/[^"]*"//;s/".*//;h;N;N;s/.*//;};/|/!b u;s/ *|.*//;H;:u;${x;s/\n//g;p;}' *.meta

Regards.
# 3  
Old 05-01-2015
Thank you, script respone is very fast.
 
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

Program to search for the files with specific format

Hi All, Your help on the below requirement is highly appreciated. I am building a program which should pick the file from a source directory and place them into target directory. While selecting the file in source it should look for some pattern in the file name. Ex: File Name 1:... (10 Replies)
Discussion started by: bharath561989
10 Replies

3. Shell Programming and Scripting

To find files having filename containing specific date format

Hi, I have a requirement to create a shell script(tcsh) that finds all the files in a directory having the file name containing date format "YYYYMMDDHHMM" and extract the date time part ""YYYYMMDDHHMM" for further processing. Could you please have any idea on this. trades_201604040000.out... (6 Replies)
Discussion started by: gopal.biswal
6 Replies

4. Shell Programming and Scripting

Help required in printing in specific format

Hi All, I 'm matching two files based on the first 2 columns and then populate other fields along with subtraction of few fields. I have managed to get the output. However, is there a easier way in formatting the output as shown below instead of using additional printf for getting fixed width... (4 Replies)
Discussion started by: shash
4 Replies

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

6. Shell Programming and Scripting

Converting text files to xls through awk script for specific data format

Dear Friends, I am in urgent need for awk/sed/sh script for converting a specific data format (.txt) to .xls. The input is as follows: >gi|1234|ref| Query = 1 - 65, Target = 1677 - 1733 Score = 8.38, E = 0.6529, P = 0.0001513, GC = 46 fd sdfsdfsdfsdf fsdfdsfdfdfdfdfdf... (6 Replies)
Discussion started by: Amit1
6 Replies

7. UNIX for Dummies Questions & Answers

Printing lines with specific strings at specific columns

Hi I have a file which is tab-delimited. Now, I'd like to print the lines which have "chr6" string in both first and second columns. Could anybody help? (3 Replies)
Discussion started by: a_bahreini
3 Replies

8. UNIX for Dummies Questions & Answers

Printing records in different format

Hi all, I have a input file say record.txt hostname IP_address Port_No Version A 10.10.10.1 80 6.02 B 10.10.10.2 81 6.03 C 10.10.10.3 82 6.04 row 1 has 4 field headings : hostname, IP_address, Port_No and Version. and from 2nd row onwards the actual records start. now i need to... (2 Replies)
Discussion started by: PranavEcstasy
2 Replies

9. Shell Programming and Scripting

Assigning a specific format to a specific column in a text file using awk and printf

Hi, I have the following text file: 8 T1mapping_flip02 ok 128 108 30 1 665000-000008-000001.dcm 9 T1mapping_flip05 ok 128 108 30 1 665000-000009-000001.dcm 10 T1mapping_flip10 ok 128 108 30 1 665000-000010-000001.dcm 11 T1mapping_flip15 ok 128 108 30... (2 Replies)
Discussion started by: goodbenito
2 Replies

10. UNIX for Dummies Questions & Answers

printing out procedures in unknown format

Does Anybody know how to print procedures written in this format? .. .nr PS 11 .nr VS 14 .nr LL 6.5i .ad l .DA 1/9/91 .in 4.0i .DS Shepard D. Johnson .DE .in 0i .sp .sp .sp .LG .ce .B Pressure Sensors (P/N 16-0018-0 & 16-0018-1) Test Procedure (1 Reply)
Discussion started by: rjtrjt
1 Replies
Login or Register to Ask a Question