Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to replace characters using sed?

Posted on 2011-03-18
2
Medium Priority
?
325 Views
Last Modified: 2012-05-11
Dear experts,

I have many files containing a line as below:

GPEHDownloadAll = "0"

I want to change this line in these files to:

GPEHDownloadAll = "0" ----> GPEHDownloadAll = "1"  (zeros will be one)

Note: Be careful of spaces between equal sign.

Can you help me using sed for this?

BR,
0
Comment
Question by:GurcanK
  • 2
2 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 35165173
sed  's/GPEHDownloadAll = "0"/GPEHDownloadAll = "1"/' inputfile

Or is there not always the same number of spaces?

wmp
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 35165220
Sorry, I just saw "many files"

grep -l 'GPEHDownloadAll = "0"' * | xargs -I{} sed  -i 's/GPEHDownloadAll = "0"/GPEHDownloadAll = "1"/' {}

Attention - the above will change the files "in place"!
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question