The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to Redirect the error messages from Syslog file to our own Application Log File balasubramaniam HP-UX 3 04-17-2008 10:44 AM
Remove Similar Lines from a File Nysif Steve Shell Programming and Scripting 3 09-04-2007 07:20 AM
Remove Similar entries in a File Nysif Steve UNIX for Advanced & Expert Users 1 08-30-2007 11:58 AM
replace a similar field in a file chiru_h Shell Programming and Scripting 2 11-01-2006 01:23 PM
Collecting data from TOP to a file sssow UNIX for Dummies Questions & Answers 5 09-06-2001 04:38 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-14-2008
Registered User
 

Join Date: Jan 2008
Location: India
Posts: 1
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.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 01-16-2008
dj -------
 

Join Date: Feb 2007
Location: Cochin, India
Posts: 332
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
Reply With Quote
  #3 (permalink)  
Old 01-16-2008
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Milan, Italy/Varna, Bulgaria
Posts: 1,432
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.
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:28 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0