1

I have a log file as below:

/export/home/got/logs/o2877612.01:job_1432787863184_159408 Message: org.apache.pig.backend.executionengine.ExecException: ERROR 2118: Input path does not exist: /user/got/distro
/export/home/got/logs/o2877612.01:Module: SUMMARY_PIG

I want to form a final log file by combining two lines as below. Above both lines start with /export/home/got/logs/o2877612.01:

/export/home/got/logs/o2877612.01:Module: SUMMARY_PIG :job_1432787863184_159408 Message: org.apache.pig.backend.executionengine.ExecException: ERROR 2118: Input path does not exist: /user/got/distro

Could you help in the unix command for this?

  • 2
    What have you tried so far, supply some of the code you have attempted and we will be able to help guide you better. – Drav Sloan Aug 5 '15 at 10:22
0

With awk:

awk -F: '{if($1!=a){printf "\n%s", $0}else{$1=":";print}} {a=$1}' file

Where:

  • -F: uses : as delimiter.
  • if($1!=a){...} If the a variable contains the same as the first field, print everything without a newline at the end,
  • else{...}: else print all fields except the first one.
  • {a=$1} Set the a variable used in the if clause.

Output:

/export/home/got/logs/o2877612.01:job_1432787863184_159408 Message: org.apache.pig.backend.executionengine.ExecException: ERROR 2118: Input path does not exist: /user/got/distro: Module  SUMMARY_PIG

I think you want line in the order as they appear in the logfile, not reversed as in your desired output.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.