Solved

Header columns are not arranged as mentioned in the script

Posted on 2013-01-19
6
435 Views
Last Modified: 2013-01-21
HI  GURUS

I am new to unix scripting my requirement is : The header columns to be aligned as mentioned in d44.awk   where this awk is called in sc-d44.sh

My expected and the output now is copied in Excel file.......

Your help is appreciated..
Thanks in advance
SC-D44-FILE-GEN.sh
d44.awk.txt
Book1.xlsx
0
Comment
Question by:JAruchamy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 38798372
> .. columns to be aligned as mentioned in d44.awk
where is you requirement when you already have a script (d44.awk) which aligns proper?

BTW, it's not a good idea to use awk for actions being better done by a shell, IMHO ...
0
 
LVL 19

Expert Comment

by:simon3270
ID: 38799049
There do indeed seem to be a lot more "system" calls than you'd normally see in an awk script!

I think the problem is that you are writing to output_dir lastf ".header" using two methods - some lines from within awk, and many more through the shell.  awk doesn't know that the shell has written to the file, so when it gets to the line which writes "Batch_Id", it thinks that the write pointer is still where it left it after writing the "Logical Data Source Code" word, so "Batch_Id" immediately follows "Logical Data Source Code".

I can think of two possible fixes.  One is to use "system" calls to write the Batch_* headings, the other is to close the .header file immediately after the last "system" call (the "-23 month" one), then the Batch_Id line will reopen the file and add to the end of that header line.
0
 
LVL 19

Accepted Solution

by:
simon3270 earned 500 total points
ID: 38799270
To clarify the "close" option:

        system("date --date='" $3 " -23 month 15 days' +%b-%Y >> " output_dir lastf ".header");
        close(output_dir lastf ".header");
        printf( "%s\t", "Batch_Id" ) >> output_dir lastf ".header";
        printf( "%s\t", "Batch_Step_Run_Id" ) >> output_dir lastf ".header";
        printf( "%s\n", "Batch_Run_Number" ) >> output_dir lastf ".header";

and the "system" option:

        system("date --date='" $3 " -23 month 15 days' +%b-%Y >> " output_dir lastf ".header");
        system("printf '%s\t' Batch_Id >> " output_dir lastf ".header");
        system("printf '%s\t' Batch_Step_Run_Id >> " output_dir lastf ".header");
        system("printf '%s\n' Batch_Run_Number >> " output_dir lastf ".header");

I've also changed the \t after the "Batch_Run_Number" to a \n in both examples, to end the line cleanly.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Closing Comment

by:JAruchamy
ID: 38802636
system("printf '%s\t' Batch Id >> " output_dir lastf ".header");
        system("printf '%s\t' Batch Step Run Id >> " output_dir lastf ".header");

But the thing is now  the output is aligned after month but the
batch in one tab ,id in one tab whereas i should have bacth id in one tab
EX:
Month24 batch id batch step run id
0
 
LVL 2

Author Comment

by:JAruchamy
ID: 38802648
the output file  is attached for the present result
example.xls
0
 
LVL 19

Expert Comment

by:simon3270
ID: 38803341
The argument needs to be a single word, with no spaces.  \either add back in the underscores (e.g. "Batch_Ifd"), or enclsose the words in quotes, e.g.:

    system("printf '%s\t' 'Batch Id' >> " output_dir lastf ".header");

Otherwise, looking good!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question