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
Fast way of find and replace, help jkl_jkl Shell Programming and Scripting 1 03-06-2008 07:41 AM
Perl: Search for string on line then search and replace text Crypto Shell Programming and Scripting 4 01-04-2008 10:24 AM
What's the fast way to delete these files? tonyvirk UNIX for Dummies Questions & Answers 4 01-01-2008 08:02 PM
Need to search and replace in multiple files in directory hierarchy umen Shell Programming and Scripting 3 12-24-2007 04:56 AM
Search and replace multi-line text in files marz Shell Programming and Scripting 10 10-10-2005 08:05 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-25-2008
dbsurf dbsurf is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 23
fast search and replace in all files

Hi

I need to find one string in all files and replace tht string with blank space and need to redirect all the files into the same directory again.

now i am using

find ./ -name "*.dmp" | xargs perl -pi -e 's/\\N//g' | sed 's/.$//g'

but now its not redirrecting properly .

its taking too much time for this operation.

Is there any way to search and replace very fast in all thousand files quickly without looping.
  #2 (permalink)  
Old 01-25-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,643
This removes \N, replaces it with " "and then chops off the last character of each line and inserts a space there. Do you know about dos2unix (or dos2ux)?

Code:
find ./ -name "*.dmp" | xargs perl -pi -e 's/\\N/ /g; s/.$/ /g'
If you want it to run faster try using background processes:
Code:
cnt=0
find ./ -name "*.dmp" |\
while read file do
  perl -pi -e 's/\\N/ /g; s/.$/ /g'  $file  &
  cnt=$cnt+1
  z=$(( $cnt % 10 ))
  if [[ $z -eq 0 ]] ; then
     wait
  fi
done 
wait
This runs ten process at the same time in background. And then waits for completion. The code you proivided does not replace the characters with a space

Last edited by vgersh99; 01-25-2008 at 02:43 PM.. Reason: missing ']'
  #3 (permalink)  
Old 01-25-2008
dbsurf dbsurf is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 23
Hi its giving error message with the use above code
syntax error at line 7: ']' unexpected
  #4 (permalink)  
Old 01-25-2008
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,116
I've edited the original posting by Jim.
  #5 (permalink)  
Old 01-25-2008
dbsurf dbsurf is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 23
Hi

Is it working?

Is it possible to replace the below sed syntax also to the above xargs perl
scenario
sed -e :a -e '/;$/!N;s/\n//; ta' -e 's/;$//' file
  #6 (permalink)  
Old 01-25-2008
KevinADC KevinADC is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2008
Posts: 731
Really, the requirements are ridiculous. There is no way to search and replace anything in thousands of files quickly. You might find some ways to faster than others, but nothing is going to be a magic bullet. I suggest you try perls inplace editor, it might be faster than sed although I don't really know.
  #7 (permalink)  
Old 01-25-2008
dbsurf dbsurf is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 23
Hi kevin

Do u know how to replace sed with perl in the below syntax

sed -e :a -e '/;$/!N;s/\n//; ta' -e 's/;$//' file
Sponsored Links
Closed Thread

Bookmarks

Tags
linux

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 04:57 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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