Visit Our UNIX and Linux User Community


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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Getting required fields from a test file in required fromat in unix
# 1  
Old 07-22-2009
Getting required fields from a test file in required fromat in unix

My data is something like shown below.
Code:
date1 date2 aaa bbbb ccccc
date3 date4 dddd eeeeeee ffffffffff ggggg hh

I want the output like this
Code:
date1date2 aaa eeeeee

I serached in the forum but didn't find the exact matching solution. Please help.
# 2  
Old 07-22-2009
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.
# 3  
Old 07-22-2009
Removed cause the comment appeared twice.

Last edited by rakeshawasthi; 07-22-2009 at 10:26 AM.. Reason: Dont know how it appeared twice.
# 4  
Old 07-22-2009
Thanks for the comment Rakeshawasthi..Here is the actual data

Code:
(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

Code:
(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

# 5  
Old 07-22-2009
You can use a awk script named "test.awk" like this:
Code:
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 :
Code:
awk -f test.awk yourfile.txt

hope that helps.
# 6  
Old 07-22-2009
Thanks for the reply

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.

Code:
(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
Code:
(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
# 7  
Old 07-22-2009
It's because you change your input. Use ur old file with "unnecessary fields" and u'll probably get the desire output ^_^

Previous Thread | Next Thread
Test Your Knowledge in Computers #991
Difficulty: Medium
System V was known inside Bell Labs as Unix 6.0.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to search a text in file and retrieve required lines following it with UNIX command?

I have requirement to search for a text in the file and retrieve required lines that is user defined with unix command. Eg: Find the text UNIX in the below file and need to return Test 8 & Test 9 Test 1 Test 2 Test 3 Test 4 UNIX Test 5 Test 6 Test 7 Test 8 Test 9 Result can... (8 Replies)
Discussion started by: Arunkumarsak4
8 Replies

2. Shell Programming and Scripting

Help required in UNIX commands

I have 40000 records in a file where i need to change the 7th field date format from 05142016 to 20160514 I have given field below. any help would be highly appreciated. 364512|9999999|9999999|210553|195495477|195257095|05142016|10009|36313 ---------- Post updated at 05:02 AM... (2 Replies)
Discussion started by: arun888
2 Replies

3. Shell Programming and Scripting

How to Modify a file content in UNIX and sort for only required fields ?

I have the below contents in a file after making the below curl call curl ... | grep -E "state|Rno" | paste -sd',\n' | grep "Disconnected" > test "state" : "Disconnected",, "Rno" : "5554f1d2" "state" : "Disconnected",, "Rno" : "10587563" "state" : "Disconnected",, "Rno" :... (2 Replies)
Discussion started by: Vaibhav H
2 Replies

4. Shell Programming and Scripting

Pattern Matching and extracting the required fields in Perl

Hi All, I am writing the following Perl Scrip and need your help in Pattern matching : I have the following Shell Script that would read line by line from the file (file_svn) and would inturn calls the Perl Script: #!/bin/bash perl_path="/home/dev/filter"... (2 Replies)
Discussion started by: filter
2 Replies

5. Shell Programming and Scripting

Unix script required

I have a file 123.txt which is aasaasas=1 bsasasasasa=2 sawqas=3 I want my output to be 1 2 3 I am new to scripting can some1 help me out. (14 Replies)
Discussion started by: karthikkasarla
14 Replies

6. Shell Programming and Scripting

Getting required fields from a text file in UNIX

My data is something like as shown below. Out of this i want the details of alarms (ex: 1947147711,1947147081......) and the fields( ex :sw=tacmwafabb9:shelf=1:slot=5-2:pport=2) Once i have these details separated, i want the count of these excluding the duplicates. What is the best possible way... (7 Replies)
Discussion started by: rdhanek
7 Replies

7. Shell Programming and Scripting

Help required on process in unix

What are some ways to tell if a given file is presently being used by a process? How can you tell what sort of access the process has to the file (read from, written to, filehandle held open, etc)? Can more than one process access the file at the same time? (2 Replies)
Discussion started by: choco4202002
2 Replies

8. UNIX for Advanced & Expert Users

Required unix command!!!

Hi, In a file I have data like... -rw-r----- 1 ftpuser users 1036695 Jul 6 14:59 ./APRIL 2007/Ujjain/My Disc (D)/9565DW07.04B -rw-r----- 1 ftpuser users 124080 Jul 6 14:59 ./APRIL 2007/Vadodara/vad_APRIL07/2082DW07.04B The above data is extracted using "find . -name... (12 Replies)
Discussion started by: ronald_brayan
12 Replies

9. UNIX for Dummies Questions & Answers

Help Required in Unix Command

Hi All, Can anyone please help me in unix command Query: ==== File contains data along with date and time stamp like, .. Date: 08:23:2005 01:00:00 method: xyz init variables Date 08:23:2005 01:00:01 method: xyz finished init variable .... (2 Replies)
Discussion started by: thaduka
2 Replies

10. Solaris

unix command required.

I need to get a few details from the command line. I need to get the kilobytes per second that my server is transfering to another or has available and I need to test the connection to make sure that its a sound connection. I also need to keep track of the response time. I have been playing... (1 Reply)
Discussion started by: nowayin
1 Replies

Featured Tech Videos