LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 07-09-2006, 08:01 PM   #1
drkstr
Senior Member
 
Registered: Feb 2006
Location: Seattle, WA: USA
Distribution: Slackware 11.0
Posts: 1,191

Rep: Reputation: 45
filesize limit on 'cat $file | sed > $file'


I wrote a little bash script to replace text in all files in a directory and it's sub-directories but it seems to only dump up to 68 Kb back into the file.
Code:
...
find $DIR -type f | while read file    #check all files in $DIR
do
  cat $file | sed -e 's/'$IN_TXT'/'$OUT_TXT'/g' > $file
done
...
Anyone have any idea how to get around this?

thanks!
...aaron
 
Old 07-09-2006, 08:54 PM   #2
spooon
Senior Member
 
Registered: Aug 2005
Posts: 1,755

Rep: Reputation: 51
i'll just repost what i posted in the other thread:

Quote:
Originally Posted by drkstr
Code:
...
find $DIR -type f | while read file
do
  cat $file | sed -e 's/'$IN_TXT'/'$OUT_TXT'/g' > $file
done
...
why not just something like
Code:
find $DIR -type f -exec sed -i 's/'$IN_TXT'/'$OUT_TXT'/g' '{}' \;
note that doing sed on a file and then redirecting it back to the same file doesn't really work, since ">" truncates the file, so you should use "sed -i" to operate on the file in-place
 
Old 07-10-2006, 02:47 AM   #3
drkstr
Senior Member
 
Registered: Feb 2006
Location: Seattle, WA: USA
Distribution: Slackware 11.0
Posts: 1,191

Original Poster
Rep: Reputation: 45
Quote:
note that doing sed on a file and then redirecting it back to the same file doesn't really work, since ">" truncates the file, so you should use "sed -i" to operate on the file in-place
arrgg! I must have read the man page 5 times and missed that option every time. I even read a few HOWTO's and they said you can't sed a file into itself; but there it is, right there in the man page. Thanks for the help, I got impatient and ended up doing this:

note: the file names were changed also to send the output to a diffrent file (I only ran into the problem when pipeing back into the source file.

Code:
mkdir `find $DIR -type d | sed -e 's/'$IN_TXT'/'$OUT_TXT'/g'`
for file in $(find $DIR)
do
  cat $file | sed -e 's/'$IN_TXT'/'$OUT_TXT'/g' \
  >  `echo $file | sed -e 's/'$IN_TXT'/'$OUT_TXT'/g'`
done
This worked, but is quite clunky. I need to learn to be more elegant in my Linux'ing.

Next time I will try your method as it is much simpler.

thanks!
...aaron

Last edited by drkstr; 07-10-2006 at 02:50 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
cat [file] | grep --- trouble bob_man_uk Linux - General 12 03-10-2006 06:05 AM
trying to redirect text to a file to cat at later point. says file doesn't exist. dr_zayus69 Programming 1 10-02-2005 08:10 AM
Printing a new file over the old file using cat mrobertson Programming 4 07-07-2005 10:18 AM
Cat with Binary File? Xaque208 Linux - General 1 12-06-2004 07:59 PM
how to delete file created as cat > --vp manikanth04 Linux - General 2 10-03-2004 06:51 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration