The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages here.

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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-14-2008
ashish.kapil ashish.kapil is offline
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.
  #2 (permalink)  
Old 01-16-2008
dennis.jacob dennis.jacob is offline Forum Advisor  
dj -------
  
 

Join Date: Feb 2007
Location: Singapore/Bangalore/Cochin
Posts: 569
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 (permalink)  
Old 01-16-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,847
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:52 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0