![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Fast way of find and replace, help | jkl_jkl | Shell Programming and Scripting | 1 | 03-06-2008 04:41 AM |
| Perl: Search for string on line then search and replace text | Crypto | Shell Programming and Scripting | 4 | 01-04-2008 07:24 AM |
| What's the fast way to delete these files? | tonyvirk | UNIX for Dummies Questions & Answers | 4 | 01-01-2008 05:02 PM |
| Need to search and replace in multiple files in directory hierarchy | umen | Shell Programming and Scripting | 3 | 12-24-2007 01:56 AM |
| Search and replace multi-line text in files | marz | Shell Programming and Scripting | 10 | 10-10-2005 05:05 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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' 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
Last edited by vgersh99; 01-25-2008 at 11:43 AM. Reason: missing ']' |
|
#3
|
|||
|
|||
|
Hi its giving error message with the use above code
syntax error at line 7: ']' unexpected |
|
#4
|
||||
|
||||
|
I've edited the original posting by Jim.
|
|
#5
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
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 |
|||
| Google The UNIX and Linux Forums |
| Tags |
| linux |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|