Header columns are not arranged as mentioned in the script


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
Who is Participating?
simon3270Connect With a Mentor Commented:
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.
> .. 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 ...
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.
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

JAruchamyAuthor Commented:
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
Month24 batch id batch step run id
JAruchamyAuthor Commented:
the output file  is attached for the present result
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!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.