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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
grep for pattern aemunathan Shell Programming and Scripting 12 05-09-2008 03:58 AM
How to grep this pattern?? askumarece Shell Programming and Scripting 13 02-20-2008 07:03 AM
help with grep the pattern bluemoon1 Shell Programming and Scripting 2 09-20-2007 12:27 PM
grep the pattern followed by newline lalelle Shell Programming and Scripting 2 08-21-2007 09:02 PM
grep for more than one pattern frustrated1 Shell Programming and Scripting 4 12-13-2005 01:49 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 Rating: Thread Rating: 2 votes, 3.00 average. Display Modes
  #1 (permalink)  
Old 10-14-2004
ssikhar ssikhar is offline
Registered User
  
 

Join Date: Nov 2003
Location: Oregon
Posts: 9
grep and sed to find a pattern and add newline

Hello All,
I have log file the result from a multithreaded process. So when a process finishes it will write to this log file as 123 rows merged.
The issue is sometimes the processess finish at the same time or write to the file at the same time as
123 rows merged.145 rows merged.
At the end of the script we do a source count from table and target count from log file. As you can see the above line will fail grep as grep will identify the line and move on while awk will take the first parameter as 123 only.
I have used the following command to correct this

grep -i "^[0-9].* rows merged" ttt | sed 's/merged\./merged\
/g' | grep -i "^[0-9].* rows merged" | sed '/^$/'d | awk '{print $1}' | while read X
do
echo $X
Y=`expr $Y + $X`
done
echo $Y
TCOUNT=${Y}
but there was another instance when this script failed because the log file has something like
Commit complete.150 rows merged.Commit complete.
The above 150 rows that were merged didn't get counted. I would like to find [0-9].* rows merged anywhere on any line and separate this pattern into a new line
EG: the above Commit complete.150 rows merged.Commit complete.
should become
Commit complete.
150 rows merged.
Commit complete.
Any help will be greatly appreciated.
Thanks
  #2 (permalink)  
Old 10-14-2004
google's Avatar
google google is offline Forum Advisor  
Moderator
  
 

Join Date: Jul 2002
Location: Atlanta
Posts: 740
Ok. Quit posting the same question twice. If people want to/are able to answer your question then they will. Be patient.
  #3 (permalink)  
Old 10-15-2004
ssikhar ssikhar is offline
Registered User
  
 

Join Date: Nov 2003
Location: Oregon
Posts: 9
Sorry didn't realize it was posted twice. I apologize. I already found a solution.
Thanks
Suresh
  #4 (permalink)  
Old 10-15-2004
jim mcnamara jim mcnamara is online now Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,770
Code:
awk '
  BEGIN{FS="."}
  {
    t=$0
    for(i=1 ; i <= NF; i++)
    {
        if ( match($i,"[0-9].* rows merged")> 0)
        {
            print $i
        }
    }
  } ' logfile
Try that as a start.
  #5 (permalink)  
Old 10-15-2004
cbkihong cbkihong is offline Forum Advisor  
Advisor
  
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,624
Duplicate threads merged

Duplicate threads/posts merged.
  #6 (permalink)  
Old 10-26-2004
ssikhar ssikhar is offline
Registered User
  
 

Join Date: Nov 2003
Location: Oregon
Posts: 9
Smile

The awk script worked very fine. The other fix I had using grep and sed to filter what I need doesn't work very well. It atleast has a tendency to fail. But the awk works just fine.
Thanks
Suresh
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 06:47 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