-2

Can you help me how use awk to scan this Control-m output ? It's a Control-m output and I need format it.

ORDERID  JOBNAME           TYPE  ODATE    STATE     STATUS FROMTIME UNTIL
-------- ----------------- ----  -------  -------   ------ -------- -----
0002daew AA60AMBI25        JOB   20160104 Wait Con
0002db84 MA34PICT01        JOB   20160105 Post pro OK
0002dc0j OPIPMJD040W       JOB   20160105 Wait Tim        1000                Deleted
0002dbw6 TR60ADCR05        JOB   20160105 Post pro OK
0002de14 WKIPEJD007W       JOB   20160106 Wait Tim NOTOK
0002dbwc OU60ADMK12        JOB   20160105 Post pro OK     0800
0002dbwd LO60LC0012        CMD   20160105 Post pro OK
0002dcxc TYCCAJD001P       JOB   20160106 Executin        2200     0500
0002dbwe OAT0ADMK13        JOB   20160105 Post pro OK     1800     0800
0002dbwf DAT60ADMK14       JOB   20160105 Post pro OK     1800     0800
0002dbxs CR60AMBI24        JOB   20160105 Post pro OK
0002dbyz LQ60ADBI24        JOB   20160105 Post pro OK

and create this output:

JOBNAME           STATUS     STATE      ODATE      FROM       UNTIL
----------------  ------     -------    -------    ----       ----
AA60AMBI25                   Wait Con   20160104
MA34PICT01       OK          Post pro   20160105
OPIPMJD040W      Deleted     Wait Tim   20160105   10:00
TR60ADCR05       OK          Post pro   20160105
WKIPEJD007W      NOTOK       Wait Tim   20160106
OU60ADMK12       OK          Post pro   20160105   08:00
LO60LC0012       OK          Post pro   20160105
TYCCAJD001P                  Executin   20160106   22:00       05:00
OAT0ADMK13       OK          Post pro   20160105   18:00       08:00
DAT60ADMK14      OK          Post pro   20160105   18:00       08:00
CR60AMBI24       OK          Post pro   20160105
LQ60ADBI24       OK          Post pro   20160105
user2707722
  • 51
  • 2
  • 8
  • 2
    You forgot to post your code. StackOverflow is about helping people fix their code. It's not a free coding service. Any code is better than no code at all. Below is a good start for you, now research `printf("%12s%10s\t%6s\n", ....(args))`. Good luck. – shellter Jan 24 '16 at 15:12
  • Your columns (e.g. "STATUS", "FROMTIME", "UNTIL") are not properly aligned. – Cyrus Jan 24 '16 at 15:35
  • 1
    If you think we know what a Control-M output is and you telling us that clearly conveys all of your requirements then you are probably going to be disappointed. Edit your question to clarify your requirements as well as posting your attempt at a solution (even pseudo-code would show some effort on your part). – Ed Morton Jan 24 '16 at 15:40
  • Welcome to SO, please show your coding efforts. – Cyrus Jan 24 '16 at 16:51

1 Answers1

2

You would do something like:

awk 'BEGIN { FIELDWIDTHS = "9 18 6 9 9 7 9 9"}  {$0 = sprintf("%100-s\n", $0); print $2 $6 " "  $5 $4 $7 $8}' cm.txt

Where

  • 'cm.txt' is your file
  • The FIELDWIDTHS list the length of the different columns, in case of fixed width columns ( e.g. when there is no suitable separator )
  • the sprintf command expands each line to 100 chars, so that the following print looks ok for short lines

Left for you:

  • add a function to format the time with a : (your desired output has this transformation)
  • specify how to deal with Deleted for orderid 0002dc0j in your example it is printed under status
Lars Fischer
  • 9,135
  • 3
  • 26
  • 35
  • No, whatever it is the OP is trying to do, that would not be the right approach. – Ed Morton Jan 24 '16 at 19:20
  • I am not quit sure if an elegant awk solution exists with the current input example. Therefore I gave the hint to use excel or to sanitize the input. At the moment I dont see how to split without explicitly giving the character ranges. – Lars Fischer Jan 24 '16 at 19:35
  • If/when the OP deigns to tell us his/her requirements, the awk solution will be trivial, it just won't involve multiple calls to awk and a pipeline between them – Ed Morton Jan 24 '16 at 19:54
  • @EdMorton You are right the two calls to awk were stupid. I changed that and also looked up the FIELDWITHS features of awk which better suits this problem. (I didnit know about that feature, so I learned somethink new.) – Lars Fischer Jan 24 '16 at 20:41
  • Unfortunately that command isn't create an output that I need: JOBNAMESTATUS STATEODATEFROMTIMEUNTIL ----------------------- --------------------------- AA60AMBI25Con Wait20160104 MA34PICT01pro Post20160105OK OPIPMJD040WTim Wait201601051000Deleted TR60ADCR05pro Post20160105OK WKIPEJD007WTim Wait20160106NOTOK OU60ADMK12pro Post20160105OK0800 LO60LC0012pro Post20160105OK TYCCAJD001P2200 Executin201601060500 OAT0ADMK13pro Post20160105OK1800 DAT60ADMK14pro Post20160105OK1800 CR60AMBI24pro Post20160105OK LQ60ADBI24pro Post20160105OK – user2707722 Jan 24 '16 at 22:36
  • You should always state it in your answer when using gawk-specific features like FIELDWIDTHS. – Ed Morton Jan 24 '16 at 23:53