GeekInterview.com
Series: Subject: Topic:
Question: 41 of 55

How would you replace the n character in a file with some xyz?

Asked by: Interview Candidate | Asked on: Jun 3rd, 2005
Showing Answers 1 - 14 of 14 Answers
shiv

Answered On : Jun 3rd, 2005

sed 's/n/xyz/g' filename > new_filename

Yes  3 Users have rated as useful.
  
Login to rate this answer.
sriku_u

Answered On : Feb 15th, 2006

View all answers by sriku_u

vi file name

then go to command mode

%s/n/xyz/g

  
Login to rate this answer.
Madhukrishnan

Answered On : Jul 10th, 2006

tail -1 sample.txt | sed 's/.$/xyz/'Check this

  
Login to rate this answer.
Bala G

Answered On : Aug 13th, 2007

using perl we can do.

perl -p -i -e "s/n/abc/g" file_name

  
Login to rate this answer.
Pradeep Singh

Answered On : Nov 7th, 2007

We can replace n characters by using the following command:
1,$s/./xyz/g
where 1 shows that the search string will start searching patterns from first line of the file.
           '.' for any character.
            g for global replacement.

  
Login to rate this answer.
BUGME

Answered On : May 30th, 2008

View all answers by BUGME

FOLLOWING IS THE ANSWER FOR REPLACING RANGE OF CHARACTERS IN A LINE OF FILE.  HERE 5TH TO 10TH CHARACTERS IN THE FILE text.txt ARE REPLACED BY "XYZ"

cut -c5-10 text.txt | sed 's/^.*$/XYZ/g'

  
Login to rate this answer.
Vivek12

Answered On : Jun 4th, 2008

View all answers by Vivek12

search for the character n in filename and replace it with xyz.
sed 's/n/xyz/g' filename

Yes  1 User has rated as useful.
  
Login to rate this answer.
sham2sushil

Answered On : Dec 14th, 2009

View all answers by sham2sushil

sed  -i  's///g'  

sed -i option will directly changed in the fine. no need to redirect the output and create the another file. Here "g" for globe change.

Shambhu

Yes  2 Users have rated as useful.
  
Login to rate this answer.
my_thoughts

Answered On : Feb 14th, 2010

View all answers by my_thoughts

After opening the file in vi editor:
come to command mode (press Esc), then type the below command

:s 1,$ s/n/xyz/g enter

  
Login to rate this answer.
oceanblue

Answered On : May 16th, 2010

View all answers by oceanblue

All the sed replacements are by default global. It's in the vi editor that you have to specifically give "g" for global replacement.

  
Login to rate this answer.
Furkan

Answered On : Mar 30th, 2012

:1,$s/n/xyz/g

Yes  1 User has rated as useful.
  
Login to rate this answer.
venkatachalam babu

Answered On : Dec 10th, 2012

:%s/n/xyz/g
Also be used in VI editer, % means globally

  
Login to rate this answer.
jbaker

Answered On : Jan 9th, 2013

Also can be done with :g/n/s//xyz/g

  
Login to rate this answer.
nitin

Answered On : Mar 2nd, 2013

cat cc | sed s/n/xyz/g

  
Login to rate this answer.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Ads

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.