Need Help: Collecting similar messages in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need Help: Collecting similar messages in a file
# 1  
Old 01-14-2008
Need Help: Collecting similar messages in a file

Hi All,

Since i am very new to shell scripting, i need help from you guys.
Suppose there is a file containing:

Log message:
Ashish

"asasasa"
asasa
asasa
asasas.info1

Log message:
Kapil

"asasasa"
asasa
asasa
asasas..info1

Log message:
Ashish

"asasasa"
asasa
asasa
asasas..info2

Log message:
Kapil

"asasasa"
asasa
asasa
asasas..info2

Log message:
Ashish

"asasasa"
asasa
asasa
asasas..info3

Now i want to create different files containing info about same log messages,which means new files should be created like this:
ashish_log_message:
containing info1..info2..info3..

Kapil_log_message:
containing info1..info2..

Hoping to get reply soon.Smilie
# 2  
Old 01-16-2008
Try this:

Code:
     for each in `sed -n '/Log message:/{n;p;}' filename | sort | uniq`
        do
        sed -n '/'$each'/{n;p;n;p;n;p;n;p;n;p;}' filename >${each}_log_message
        done

# 3  
Old 01-16-2008
With Awk:

Code:
awk '/^Log message:/{close(f);getline;f=$0"_log_message";next}{print>f}' filename

Use nawk or /usr/xpg4/bin/awk on Solaris.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Collecting header from another file

I want to add header description from a file by matching the 2nd col of another file. . The lookup file is at ftp://ftp.ncbi.nlm.nih.gov/pub/COG/KOG/kog The table file looks like comp1001565_c0_seq1 At1g14590 48.48 66 34 0 200 3 171 236 ... (1 Reply)
Discussion started by: ritakadm
1 Replies

2. Shell Programming and Scripting

Reducing text file using similar lines

Hello, I am a java programmer but want to try unix for a purpose where I need to reduce a file using its first field.. Here is the sample data: admin;2;0;; admission;8;0;; aman;1;0;; caroline;0;4;; cook;0;4;; cook;2;0;; far;0;3;; far;1;5;; I am explaining the dataset first. There... (5 Replies)
Discussion started by: shekhar2010us
5 Replies

3. Shell Programming and Scripting

extracting lines from a file with similar first name

consider i have two files cat onlyviews1.sql CREATE VIEW V11 AS SELECT id, name, FROM etc etc WHERE etc etc; CREATE VIEW V22 AS SELECT id, name, FROM etc etc WHERE etc etc; CREATE VIEW V33 AS (10 Replies)
Discussion started by: vivek d r
10 Replies

4. Shell Programming and Scripting

remove one of each similar lines in a file

Hello folks I have a question for you gurus of sed or grep (maybe awk, but I would prefer the first two) I have a file (f1) that says: (actually, these are not numbers but md5sum, but for simplicity, let's assume these numbers.) 1 2 3 4 5And I have a file (f2) that says 1|a 1|b 1|c 2|d... (3 Replies)
Discussion started by: tukuyomi
3 Replies

5. Shell Programming and Scripting

Collecting details

Hi all, I am having lots of oracle servers. I want to collect some health check details from all the server and report to one single centralized server. What would be best solution for this? OS: AIX Thanks Gopal (1 Reply)
Discussion started by: ilugopal
1 Replies

6. Shell Programming and Scripting

Collecting specific portion from a file

I have a file which contains data like a b x col1:data1 formula:data3 this is for 2 a c col1:@bkw formula:dontad ad asd as per a \ i want the data from col1 and formula to keep the col1 data in left side of excel and col2 data in right side of it (1 Reply)
Discussion started by: bmrout007
1 Replies

7. Infrastructure Monitoring

Remove Similar entries in a File

-------------------------------------------------------------------------------- I have a log file "logreport" that contains several lines as seen below: 04:20:00 /usr/lib/snmp/snmpdx: Agent snmpd appeared dead but responded to ping 06:38:08 /usr/lib/snmp/snmpdx: Agent snmpd appeared... (2 Replies)
Discussion started by: Nysif Steve
2 Replies

8. Infrastructure Monitoring

Remove Similar Lines from a File

I have a log file "logreport" that contains several lines as seen below: 04:20:00 /usr/lib/snmp/snmpdx: Agent snmpd appeared dead but responded to ping 06:38:08 /usr/lib/snmp/snmpdx: Agent snmpd appeared dead but responded to ping 07:11:05 /usr/lib/snmp/snmpdx: Agent snmpd appeared dead... (4 Replies)
Discussion started by: Nysif Steve
4 Replies

9. Shell Programming and Scripting

replace a similar field in a file

Hello, I am having a file where I have to replace the port values with the variable I defined. The file is an extract of an xml file: <NameValuePair> <name>Service1</name> <value>tcp:32406</value> </NameValuePair> <NameValuePair> ... (2 Replies)
Discussion started by: chiru_h
2 Replies

10. UNIX for Dummies Questions & Answers

Collecting data from TOP to a file

Is there a way to collect data from top command to a file at regular intervals. I need this on HP-UX. I need to gather resident memory usage. I know that sar will give %cpu usage. There is a pmap command which gives memory usage in solaris. Is there a similar command in HP-UX Thanks (5 Replies)
Discussion started by: sssow
5 Replies
Login or Register to Ask a Question