UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help
Receive the tools necessary to be the rock star of your field. Our 12-month program teaches you the evolving world of multi-channel marketing as well as the complex issues and opportunities found in the industry.

ASP Free and Iron Speed Designer are giving away $5,500+ in FREE licenses. Iron Speed's RAD CASE toolset can save up to 80% of your coding time. One free license per week, one perpetual license per month!
Download and Activate to enter!

Web development can be a daunting task, even for specialists. There is a lot of information to absorb and a lot of technologies to learn in order to manage a superior website. When trying to learn the ropes, developers need a reliable source to introduce new ideas that can be easily implemented. When working on large projects, even web veterans may run into a technology or an aspect of a technology that they are unfamiliar with.

Learn More!


Download to Enter
| Contest Rules

Tutorials | Forums

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rating: Thread Rating: 3 votes, 5.00 average. Display Modes
 
Unread Dev Shed Forums Sponsor:
  #16  
Old November 10th, 2010, 11:05 AM
swapnilverma swapnilverma is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2010
Posts: 1 swapnilverma User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 51 m 8 sec
Reputation Power: 0
I have comma separated file..

I need to remove comma between " " so that i can read each column easily with comma delimiter

Before

100,200,300,A,"34,00","64,000","0,23"

After

100,200,300,A,"3400","64000","023"

appreciate quick help

Reply With Quote
  #17  
Old September 16th, 2011, 02:54 AM
rael rael is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2011
Posts: 1 rael User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 26 m 10 sec
Reputation Power: 0
Also can be done using vim.

Code:
for file in $(grep -l "PATTERN" `find . -name "*.php"`); do vim "+%s:PATTERN:REPLACE:g" "+wq" $file; done;

Reply With Quote
  #18  
Old November 12th, 2011, 09:51 PM
stingerman stingerman is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2011
Posts: 1 stingerman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 35 sec
Reputation Power: 0
Total newbie here.

I need to replace the following text line in php files only in the entire directory, meaning many folders etc.

/content/x/x/x/xxxxx/html/

with

/xxxxxx/public_html/

Which code would work best and is this done through ssh?

Reply With Quote
  #19  
Old January 12th, 2012, 10:34 PM
geilt geilt is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2011
Posts: 1 geilt User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 32 sec
Reputation Power: 0
Quote:
Originally Posted by gare
very cool script. Thanks for posting. I modified it a bit, and this seems to work pretty well:
Code:
# *****************************************************************************************
# find_and_replace_in_files.sh
# This script does a recursive, case sensitive directory search and replace of files
# To make a case insensitive search replace, use the -i switch in the grep call
# uses a startdirectory parameter so that you can run it outside of specified directory - else this script will modify itself!
# *****************************************************************************************

!/bin/bash
# **************** Change Variables Here ************
startdirectory="/home/gare/tmp/tmp2"
searchterm="search"
replaceterm="replaceTerm"
# **********************************************************

echo "******************************************"
echo "* Search and Replace in Files Version .1 *"
echo "******************************************"

        for file in $(grep -l -R $searchterm $startdirectory)
          do
           sed -e "s/$searchterm/$replaceterm/ig" $file > /tmp/tempfile.tmp
           mv /tmp/tempfile.tmp $file
           echo "Modified: " $file
        done

echo " *** Yay! All Done! *** "


This is an amazing script. Thanks so much for i. I spent over 2 hours looking for something to do exactly this. Going into my toolbox!! =)

Reply With Quote
  #20  
Old May 1st, 2012, 04:57 PM
tunaonline1 tunaonline1 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 1 tunaonline1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 m 53 sec
Reputation Power: 0
Exclamation Perl uses a .cfg file which can't hold variables.

I have a shell script which executes one perl. The perl uses some variable which is again defined in a .cfg file. In that .cfg file I have a variable (LOG_FILE=$HOME/LOG). Since I can't use the $HOME inside the .cfg file which is used by perl, I have to each time change the .cfg file with value of $HOME, then in .cfg file I have LOG_FILE=/pkg/mt411c/LOG (as the value of $HOME=/pkg/mt411c). But everytime I copy this .cfg file to other environment I have to change the value of this LOG_FILE variable with the value of "$HOME" as it gets changed in dift env. But I want to make it generic so that I will not either change the value of $HOME inside the file or I want any other shell script which will change the value of these variables each time I put the .cfg file. (Note: I have several other variables in that .cfg file, this is just one example). Please help.

Reply With Quote
  #21  
Old May 2nd, 2012, 08:31 AM
SimonJM SimonJM is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Mar 2006
Posts: 1,917 SimonJM User rank is General 5th Grade (Above 100000 Reputation Level)SimonJM User rank is General 5th Grade (Above 100000 Reputation Level)SimonJM User rank is General 5th Grade (Above 100000 Reputation Level)SimonJM User rank is General 5th Grade (Above 100000 Reputation Level)SimonJM User rank is General 5th Grade (Above 100000 Reputation Level)SimonJM User rank is General 5th Grade (Above 100000 Reputation Level)SimonJM User rank is General 5th Grade (Above 100000 Reputation Level)SimonJM User rank is General 5th Grade (Above 100000 Reputation Level)SimonJM User rank is General 5th Grade (Above 100000 Reputation Level)SimonJM User rank is General 5th Grade (Above 100000 Reputation Level)SimonJM User rank is General 5th Grade (Above 100000 Reputation Level)SimonJM User rank is General 5th Grade (Above 100000 Reputation Level)SimonJM User rank is General 5th Grade (Above 100000 Reputation Level)SimonJM User rank is General 5th Grade (Above 100000 Reputation Level)SimonJM User rank is General 5th Grade (Above 100000 Reputation Level)SimonJM User rank is General 5th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 5 Days 11 h 32 m 43 sec
Reputation Power: 1297
This really should have been a new thread ...
There must be a few ways to acheive this - can you not include the .cfg file in the perl, for example? Is theer now way of accessing the environment variables from within perl?
__________________
The moon on the one hand, the dawn on the other:
The moon is my sister, the dawn is my brother.
The moon on my left and the dawn on my right.
My brother, good morning: my sister, good night.
-- Hilaire Belloc

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Unix find and replace text within all files within a directory


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.

© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 8 - Follow our Sitemap