• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 643
  • Last Modified:

Unix ksh compare files

Hello Experts,

Each day an extract is created.
Want needs to happen is that the file created 'today' should be compared with the file created 'yesterday'.

Each file has these values:
CPU JOB SCRIPT LOGON CREATOR
Only SCRIPT (can) have spaces in it, not so the others.
So SCRIPT becomes everything between JOB (2nd column) and LOGON (4th column)
There is no header (but it could be added).

Example of file:
BEKD1859 MAEWSTLD "C:\Program Files\IBM\TWS\app_user\bin"\rmstdlist.cmd 10 app_user app_user
BEKD1859 MQSULOGFILEPURGER exit 0 app_user app_user
BEKD1859 MQSUSAVEQMGROBJECTS-TJPMQD01 exit 0 app_user app_user
BEKD1859 MQSUSAVEQMGROBJECTS-TJPMQT01 exit 0 pbu pbu
BEKD1859 OTS-EXIT0-CMD exit 0 app_user pbu
BEKD1859 ROTATEDRFILES-TJPMQP01 exit 0 app_user app_user
BEKD1859 SEND-EMAIL-OBJECTS-TJPMQD01 exit 0 app_user app_user
BEKD1859 SEND-EMAIL-OBJECTS-TJPMQT01 exit 0 app_user app_user
BEKD1859 SEND-EMAIL-PURGE exit 0 app_user app_user
SANDBOX CREATEPOSTREPORTS /opt2/app_user/CreatePostReports app_user app_user
SANDBOX MAKEPLAN /opt2/app_user/MakePlan app_user app_user
SANDBOX OTS-EXIT0-CMD exit 0 app_user pbu
SANDBOX OTS-EXIT0-CMD1 exit 0 app_user pbu
SANDBOX OTS-EXIT0-CMD2 exit 0 app_user pbu
SANDBOX RMSCHDLG /tech/tws/scripts/rmschedlog root kna
SANDBOX RMSTDLST /tech/tws/scripts/rmstdlist app_user kna
SANDBOX STARTAPPSERVER /opt2/app_user/wastools/startWas.sh app_user app_user
SANDBOX SWITCHPLAN /opt2/app_user/SwitchPlan app_user app_user
SANDBOX UPDATESTATS /opt2/app_user/UpdateStats app_user app_user

Open in new window


So if we take first line:
CPU = BEKD1859
JOB = MAEWSTLD
SCRIPT = "C:\Program Files\IBM\TWS\app_user\bin"\rmstdlist.cmd 10
LOGON = app_user
CREATOR = app_user

Goal(s):
- check and report on new entries (CPU JOB combination)
- check and report on removed entries (CPU JOB combination)
- check and report on changed values of existing entries (SCRIPT LOGON CREATOR)

Please be so kind to check this out.
Many thanks.
0
Watnog
Asked:
Watnog
  • 2
2 Solutions
 
icenickCommented:
Hello,

I am afraid I do not understand. You have to write a script. This script will "cat" or "more" the file. You can arrange the columns with the "awk" command.

Example:

more your_file | awk '{print $1 $3}' 

Open in new window


The above command will read the file and pipe it to awk which in turn would display the first and third columns. You can display in any order you want: awk '{print $5 $1 $2 $3}'

Another way would be (since each day you have a new file) to use the command "diff". You can use the command "sort" to sort out based on a chosen column.

Read more about awk, diff and sort (by typing "man awk", "man diff", etc.).

Good Luck!
0
 
arober11Commented:
Per: icenick post, look / play with the diff command e.g.

#Difference between the files.
diff todays_file  yesterdays_file

#Compare just the CPU and JOB entries
cut -f1,2 -d' ' todays_file        | sort -u > todays_file.CPU_n_JOB
cut -f1,2 -d' ' yesterdays_file | sort -u > yesterdays_file.CPU_n_JOB
diff  todays_file.CPU_n_JOB yesterdays_file.CPU_n_JOB

Open in new window

0
 
WatnogAuthor Commented:
Yes I will. You got me a trail...
Thanks.
0
 
WatnogAuthor Commented:
Sorry for late reply, and yes this was good enough info to get in rolling. Thanks!
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now