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 > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Remove last blank line of file ruchimca Shell Programming and Scripting 2 04-08-2009 10:30 PM
Remove blank line - SED pcwiz Shell Programming and Scripting 10 11-11-2008 11:19 PM
How to allocate memory ravi3553 UNIX for Advanced & Expert Users 5 08-19-2008 10:09 AM
how allocate virtual memory munnu High Level Programming 2 04-20-2007 04:07 PM
Unix Help - allocate more memory to /tmp cmackin UNIX for Dummies Questions & Answers 1 06-01-2006 07:25 AM

Reply
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 08-18-2009
senthil.ak senthil.ak is offline
Registered User
  
 

Join Date: Jul 2009
Location: chennai
Posts: 14
Lightbulb Question: Help need to remove blank line & sed: Couldn't re-allocate memory error.

I've shell script where i used the below command to take the line which contains patterns.

Code:
sed -n "/$year 05:/,/$year 17:/p" trace.log | grep -f patterns.txt > output.log
This was working fine for long time, but now a days this script is not working with and throwing error like

sed: Couldn't re-allocate memory

when I looked for the file size its huge now a days, usually it will be less than or equal to 1.5 GB. but now a days its

Code:
$lt trace.log
 6.9G Aug 18 00:31 trace.log
trace.log is 6.9GB in size - so i conculded that the huge file size is the root cause of the issues. when i look in to the trace.log which 7 GB in size, its contains huge blank lines. i tired to remove the blank line using below commands but failed to perform and got the below error

Code:
 
$grep -av "^$" trace.log > ~/temp.tmp
$cat temp.tmp
Binary file trace.log matches
$sed '/^$/d' /logs/gopm/trace.log > ~/temp.tmp
sed: Couldn't re-allocate memory
$
Could you please suggest some other solution to over come this issue, appericaite your help
thanks
Senthil
  #2 (permalink)  
Old 08-18-2009
TonyFullerMalv's Avatar
TonyFullerMalv TonyFullerMalv is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2008
Location: Malvern, Worcs. U.K.
Posts: 730
Removed the empty lines is only going to remove 1 byte per line so it is not going to help much.

Could you do some of the:
Code:
grep -f patterns.txt"
into a temporary file and then do the:
Code:
sed -n "/$year 05:/,/$year 17:/p"
?
  #3 (permalink)  
Old 08-19-2009
senthil.ak senthil.ak is offline
Registered User
  
 

Join Date: Jul 2009
Location: chennai
Posts: 14
Even I tired the sed command alone which gives me memory error, i grepped for only empty line to a temp directory the file size is coming around 740 MB, so i think we can remove the blank lines whihc will eliminate the issue, but i dont know how to do this.

Thanks
Senthil.
  #4 (permalink)  
Old 08-19-2009
thanhdat's Avatar
thanhdat thanhdat is offline
Registered User
  
 

Join Date: Aug 2008
Location: Paris
Posts: 107
So you can try :
Code:
 grep -ve "^[ \t]*$" glpi.conf.bak | grep -f pattern.txt > temp.log
and then sed :
Code:
sed -n "/$year 05:/,/$year 17:/p" temp.log
If that doesn't work, why don't you split your huge file into smaller ones ^___^
  #5 (permalink)  
Old 08-19-2009
senthil.ak senthil.ak is offline
Registered User
  
 

Join Date: Jul 2009
Location: chennai
Posts: 14
Spliting the file is a very good option, but the problem is the sed where i'm taking 5:00 to 17:00 time log wont work at all. Becuase i dont know what time string will be come in the first and last line.

Also the main concern here is the space, i wont have enough space in my /home directory where i work for the temp.log file

bash-2.05$ grep -ve "^[ \t]*$" /logs/trace.log | grep -f ~/patterns.txt >~/temp.log
bash-2.05$ cat temp.log

but this command is generating a empty file

bash-2.05$ cat temp.log
bash-2.05$
  #6 (permalink)  
Old 08-19-2009
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,309
You can try this assuming year is a shell variable:

Code:
awk -v Y=$year '
$0 ~ Y " 05:"{p=1}
$0 ~ Y " 17:"{print;exit}
p' trace.log | grep -f patterns.txt > output.log
Regards
  #7 (permalink)  
Old 08-19-2009
senthil.ak senthil.ak is offline
Registered User
  
 

Join Date: Jul 2009
Location: chennai
Posts: 14
Franklin, could you please explain me the awk statement, cause the command is taking almost 99 % of CPU when i executed

Code:
$  ps -aux| grep 9919
sayyavu    9919 99.9  0.5 34768 22672 pts/5   R    03:22   3:07 awk -v Y= ?$0 ~ Y
also here is the sample of trace.log which will help you in finding the solution.
Code:
7811  CMA: 08/19/2009 03:30:54   UserValidationFilter.validateUser 
7811  CMA: 08/19/2009 03:30:54   UserValidationFilter.getCookieValue entry
7811  CMA: 08/19/2009 03:30:54   UserValidationFilter.getCookieValue exit
7811  CMA: 08/19/2009 03:30:54   UserValidationFilter.validateUser 
7811  CMA: 08/19/2009 03:30:54   UserValidationFilter.validateUser Current Session is Not New
7811  CMA: 08/19/2009 03:30:54   UserValidationFilter.validateUser Session Id from SSO null
7811  CMA: 08/19/2009 03:30:54   UserValidationFilter.validateUser Before sm_universalid
7811  CMA: 08/19/2009 03:30:54   UserValidationFilter.validateUser After sm_universalid
7811  CMA: 08/19/2009 03:30:54   UserValidationFilter.validateUser exit
6332  PrePr: 08/19/2009 03:30:54   ValidateUserRequestProcessor.processPreprocess entry
6332  PrePr: 08/19/2009 03:30:54   ValidateUserRequestProcessor.getGuid
The bold letter which i want to grep so i am using the sed with year then hour.

Code:
sed -n "/$year 05:/,/$year 17:/p" trace.log
Regards,
senthil.
Reply

Bookmarks

Tags
grep -v, sed awk bash shell

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 03:27 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