Getting required fields from a test file in required fromat in unix

My data is something like shown below.

date1 date2 aaa bbbb ccccc
date3 date4 dddd eeeeeee ffffffffff ggggg hh

I want the output like this

date1date2 aaa eeeeee

I serached in the forum but didn't find the exact matching solution. Please help.

Please share the detailed requirement with atleast 5-10 lines of sample and 4-5 lines of desired output.
Also list down the conditions to reach to the desired output.
Your query is bit ambiguous. Please do that so that someone can help you.

Removed cause the comment appeared twice.

Thanks for the comment Rakeshawasthi..Here is the actual data

(05/17/2009 00:25:00.000)(:)  Port Search Parameters: (Dictionary (#pport->'1' #channel->'1-3-1' #link->'1-3-1' #sw->'GRPSOR29BB4' #group->'10' #shelf->'1' #
slot->'1' ))
(05/17/2009 00:25:04.000)(:)  Alarm processed:1945372343 Severity:2
(05/17/2009 00:25:04.000)(:)  Port Search Parameters: (Dictionary (#shelf->'1' #sw->'LKWDCOMABBA' #slot->'16-2' #pport->'7' ))
(05/17/2009 00:25:06.000)(:)  Alarm processed:1945372438 Severity:4
(05/17/2009 00:25:07.000)(:)  Port Search Parameters: (Dictionary (#pport->'1' #channel->'3-3-2' #link->'3-3-2' #sw->'SLKCUTMABBE' #group->'10' #shelf->'1' #
slot->'7' ))
(05/17/2009 00:25:10.000)(:)  Alarm processed:1945373313 Severity:2
(05/17/2009 00:25:10.000)(:)  Port Search Parameters: (Dictionary (#lport->'1' #sw->'DNVRCODCDSQ' #slot->'7' #pport->'1' #channel->'27' ))
(05/17/2009 00:25:11.000)(:)  Found No Ticket Create Rule: 373316
(05/17/2009 00:25:11.000)(:)  Port Search Parameters: (Dictionary (#shelf->'1' #sw->'FARGNDBCBB3' #slot->'12-2' #pport->'5' ))
(05/17/2009 00:25:12.000)(:)  Alarm processed:1945372747 Severity:4
(05/17/2009 00:25:12.000)(:)  Port Search Parameters: (Dictionary (#pport->'1' #channel->'2-6-2' #link->'2-6-2' #sw->'ALBQNMMABBH' #group->'9' #shelf->'1' #s
lot->'2' ))

The required output is

(05/17/2009 00:25:00.000) (05/17/2009 00:25:04.000)  1945372343
(05/17/2009 00:25:04.000) (05/17/2009 00:25:06.000)  1945372438
(05/17/2009 00:25:07.000) (05/17/2009 00:25:10.000)  1945373313

You can use a awk script named "test.awk" like this:

BEGIN {FS = "  "}
{
   if ($0 ~ /Port/) {date1=substr($1,1,index($1,"(:") - 1)}
   if ($0 ~ /Alarm/) {date2=substr($1,1,index($1,"(:") - 1)
   print date1,date2,substr($2,17,11)}
}

and run it :

awk -f test.awk yourfile.txt

hope that helps.

Hi,

Thanks for your reply. But that is not working..it just gave me a blank screen. Mean while i have removed unnecessary fields from my input.

(05/17/2009 00:24:24.000)(:) Port Search
(05/17/2009 00:24:26.000)(:) Alarm processed:1945373047
(05/17/2009 00:24:26.000)(:) Port Search
(05/17/2009 00:24:31.000)(:) Alarm processed:1945373093
(05/17/2009 00:24:31.000)(:) Port Search
(05/17/2009 00:24:32.000)(:) Alarm processed:1945373111
(05/17/2009 00:24:32.000)(:) Channel Search
(05/17/2009 00:24:33.000)(:) Alarm processed:1945373076

But the output to get remiains the same

(05/17/2009 00:24:24.000) (05/17/2009 00:24:26.000) 1945373047
(05/17/2009 00:24:26.000) (05/17/2009 00:24:31.000) 1945373093
--------------

Please help

It's because you change your input. Use ur old file with "unnecessary fields" and u'll probably get the desire output :slight_smile:

I did try with my old input only. But there is some change in the input file. I think i need to use port/channel in the first line of the test.awk file.

if ($0 ~ /Port/) {date1=substr($1,1,index($1,"(:") - 1)}

Thanks for your help