?
Solved

Header columns are not arranged as mentioned in the script

Posted on 2013-01-19
6
Medium Priority
?
444 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 2000 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
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

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

Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.
Suggested Courses
Course of the Month9 days, 16 hours left to enroll

762 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