Perl & Sed command -- Out of Memory Error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl & Sed command -- Out of Memory Error
# 1  
Old 09-06-2010
Perl & Sed command -- Out of Memory Error

Experts,

We used to receive our source files with '~^' as row delimiter. This file contains 2500K records and two of the columns having value in HTML formats within the file.

While running the below commands against the file, we are encountering out of memory, could you please help to identify why this error is coming out and what way can be fixed. We used to run this piece of code for several other files and it is working properly.

Code:
perl -pi -e 's/~\^/^F/g' Srik001.dat (out of memory error)

Code:
Sed 's/~\^/^F/g' Srik001.dat > Srik.dat (failed to allocate memory error)

Thanks in advance

Thanks & regards
Srik

Moderator's Comments:
Mod Comment There is no need to format each line on it's own. And please use code tags for command lines, listings, console output, and other similar texts

Last edited by pludi; 09-06-2010 at 08:18 AM..
# 2  
Old 09-06-2010
To avoid reading all the data into memory, you need to tell the program to change its idea of records:
Code:
perl -e'$/="~^";$\="\6";chomp&&print while<>' Srik001.dat

If the last record doesn't have the separator, it will not be included in the output.
This User Gave Thanks to binlib For This Post:
# 3  
Old 09-14-2010
Could you please provide any other alternate solution to this problem
Thanks
Srik

Quote:
Originally Posted by binlib
To avoid reading all the data into memory, you need to tell the program to change its idea of records:
Code:
perl -e'$/="~^";$\="\6";chomp&&print while<>' Srik001.dat

If the last record doesn't have the separator, it will not be included in the output.
# 4  
Old 09-14-2010
MySQL

try this Smilie is usefull when occurs overflow mem arg buffer or pattern or hold buffer or ...
Code:
while read -r l ; do sed 's/~\^/^F/g' "$l" >>Srik.dat ; done <Srik001.dat

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problems with ampersand (&) in sed command

Hello everybody, I have a Problem with sed command. I want to replace a defined string with a string from a database field (dynamic). e.g. sed -i -e 's/%NAME%/'"$HNAME"'/g' The Problem is that the $HNAME variable can contain Special characters like '&' e.g. HNAME="AH Kruger & Co. KG" ... (1 Reply)
Discussion started by: Bambuti2000
1 Replies

2. Shell Programming and Scripting

Perl or sed command ?

Hi Guys Am working on a bash script but got stuck, in this line: 32 $configValues = ''; What would be the best command to enter the password between the " Perl or sed ? Been trying with Perl using this command: perl -pi -e 's/''/Seattle#1669!/g'... (5 Replies)
Discussion started by: Tox
5 Replies

3. Homework & Coursework Questions

sed & cut command issues

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: After using the egrep command to pull certain lines from the asg5f1 (creating the asg5f1c file), I am required... (1 Reply)
Discussion started by: robrom78
1 Replies

4. Shell Programming and Scripting

applescript & grep - sed command

I'm new using Unix commands in applescript. The following script you choose different folders with PDfs, get file count of PDfs on chosen folders, & write the results in text file. set target_folder to choose folder with prompt "Choose target folders containing only PDFs to count files" with... (0 Replies)
Discussion started by: nellbern
0 Replies

5. UNIX for Dummies Questions & Answers

Grep char count & pipe to sed command

Hi I am having a 'grep' headache Here is the contents of my file: (PBZ,CP,(((ME,PBZ,BtM),ON),((ME,((PBZ,DG),(CW9,PG11))),CW9,TS2,RT1))) I would like to count out how many times 'PBZ' occurs and then place that number in the line above 3... (8 Replies)
Discussion started by: cavanac2
8 Replies

6. Shell Programming and Scripting

Convert Sed command to perl command

Hello, Can any perl experts help me convert my sed string to perl. I am unsuccessful with this. I have to remove this string from html files OAS_AD('Top'); I have come up with this. However the requirement is in perl. for find in $(find . -type f -name "file1.html") ; do cat $find |... (2 Replies)
Discussion started by: abacus
2 Replies

7. UNIX for Dummies Questions & Answers

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. 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:... (8 Replies)
Discussion started by: senthil.ak
8 Replies

8. Shell Programming and Scripting

[Perl] Accessing array elements within a sed command in Perl script

I am trying to use a script to replace the header of each file, whose filename are stored within the array $test, using the sed command within a Perl script as follows: $count = 0; while ( $count < $#test ) { `sed -e 's/BIOGRF 321/BIOGRF 332/g' ${test} > 0`; `cat 0 >... (2 Replies)
Discussion started by: userix
2 Replies

9. Shell Programming and Scripting

What's wrong with this sed command? delete & append

I want to write a sed command that does the following work: file: <a>asdfasdf<\s> <line>hello</line> <b>adf<\c> <b>tttttttt<\c> output: name=hello sed -e 's/^*//' -n -e '/<line>/s/<*>//gp;' -e 's/^/name="/g' file but I can not append "=" after getting the line with... (5 Replies)
Discussion started by: minifish
5 Replies

10. Shell Programming and Scripting

cp & sed error

Hi, Below is a small piece of my Korn shell script - what i am trying to do is substitute all occurrences of the word given by the ${src} parameter with the word given by the ${dest} parameter in that particular textfile. But i get the errors below... for i in `ls... (19 Replies)
Discussion started by: n8575
19 Replies
Login or Register to Ask a Question