Solved

Header columns are not arranged as mentioned in the script

Posted on 2013-01-19
6
426 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
  • 3
  • 2
6 Comments
 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
> .. 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
Comment Utility
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
Comment Utility
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 Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 2

Author Closing Comment

by:JAruchamy
Comment Utility
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
Comment Utility
the output file  is attached for the present result
example.xls
0
 
LVL 19

Expert Comment

by:simon3270
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now