Solved

Header columns are not arranged as mentioned in the script

Posted on 2013-01-19
6
439 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
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 
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

More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

Question has a verified solution.

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

I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

691 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