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

Showing Answers 1 - 1 of 1 Answers

shiv

  • Jun 3rd, 2005
 

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

Madhukrishnan

  • Jul 10th, 2006
 

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

  Was this answer useful?  Yes

Bala G

  • Aug 13th, 2007
 

using perl we can do.

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

  Was this answer useful?  Yes

Pradeep Singh

  • 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.

  Was this answer useful?  Yes

BUGME

  • May 30th, 2008
 

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'

  Was this answer useful?  Yes

sham2sushil

  • Dec 14th, 2009
 

sed  -i  's/<Search_word>/<Replacing_word>/g'   <filename>

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

oceanblue

  • May 16th, 2010
 

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

  Was this answer useful?  Yes

venkatachalam babu

  • Dec 10th, 2012
 

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

  Was this answer useful?  Yes

jbaker

  • Jan 9th, 2013
 

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

  Was this answer useful?  Yes

nitin

  • Mar 2nd, 2013
 

cat cc | sed s/n/xyz/g

  Was this answer useful?  Yes

shanmugaraj

  • Nov 14th, 2013
 

sed s/n/xyz/g filename

n -character want to replace
xyz - new character/word to insert

  Was this answer useful?  Yes

Rapolu Venkateshwarlu

  • Dec 12th, 2013
 

nw=`cat filename|cut -f -d `|sed -i "s/$nw/

  Was this answer useful?  Yes

ajay goel

  • Jun 15th, 2014
 

Code
  1. ### general method for n number of file#####

  2.  

  3. for file in path/*

  4. do

  5. if [ -f $file ];

  6. then

  7. sed s/n/xyz/g $file

  8. else

  9. echo " $file is not file"

  10. fi

  11. done

  12.  

  Was this answer useful?  Yes

Arun C N

  • Jun 24th, 2014
 

sed -n s/n/xyz/g filename

  Was this answer useful?  Yes

priya

  • Jan 19th, 2015
 

sed s/xyz/n/g filename

  Was this answer useful?  Yes

pankaja das

  • Jan 30th, 2015
 

sed s/xyz/n/g filename

  Was this answer useful?  Yes

sambit

  • Mar 28th, 2017
 

you dont need /g at the end for removing only the nth occurrence. You need g for replacing globally. The answer is:
sed s/string_to_replace/string_to_replace_with/n file_name
where "n" is the position where you want to do the replacement.

  Was this answer useful?  Yes

Give your answer:

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

Answer Question

Click here to Login / Register your free account


 
Send   Reset

 

Related Answered Questions

 

Related Open Questions