Sed character substitution


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sed character substitution
# 1  
Old 09-04-2009
Bug Sed character substitution

Hi

I have to replace in around 60 files a word an replcae it by another

Suppose all the files have a word intelligent i want to replace it by idiot

I am planning to use sed for executing this job


Code:
sed 's/\intelligent/idiot/g'

I plan to have a file (test.txt) which contains list of all 60 files which are to be edited

Code:
cat test.txt | while read line 
 
do

here i am a bit stuck up .. How do i proceed so that the script reads the file names from test.txt and perform a
sed 's/\intelligent/idiot/g'

please help

Last edited by vgersh99; 09-04-2009 at 03:26 PM.. Reason: code tags, PLEASE!
# 2  
Old 09-04-2009
Code:
#!/bin/ksh

while read i
do
  echo $i
  printf '1,$s/intelligent/idiot/g\nwq!\n' | ex -s "${i}"
done < test.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed searches a character string for a specified delimiter character, and returns a leading or traili

Hi, Anyone can help using SED searches a character string for a specified delimiter character, and returns a leading or trailing space/blank. Text file : "1"|"ExternalClassDEA519CF5"|"Art1" "2"|"ExternalClass563EA516C"|"Art3" "3"|"ExternalClass305ED16B8"|"Art9" ... ... ... (2 Replies)
Discussion started by: fspalero
2 Replies

2. UNIX for Beginners Questions & Answers

(g)awk conditional substitution issues when attempting to delete character

A portion of my input is as follows: 1087 IKON01,49 A WA- -1 . -1 . 0 W WA- -1 . -1 . 0 . -1 . -1 -1 -1 -1 -1 -1 W 1088 IKON01,49 A J.@QU80MW. 2... (2 Replies)
Discussion started by: jvoot
2 Replies

3. Shell Programming and Scripting

ksh - Get last character from string - Bad Substitution error

I want to get the last character from my machine name using the following code, the default shell is bash, the script runs in ksh. I get 'bad' substitution error on running the script, but works fine if run using dot and space. Why? $ echo $0 bash $ cat -n myenv.sh 1 ... (8 Replies)
Discussion started by: ysrini
8 Replies

4. Shell Programming and Scripting

Sed: delete on each line before a character and after a character

Hi there, A total sed noob here. Is there a way using sed to delete everything before a character AND after another character on each line in a file? The deletion should also delete the indicating characters(here: an opening and a closing parenthesis). The original file would look like... (3 Replies)
Discussion started by: bnbsd
3 Replies

5. Shell Programming and Scripting

KSH: substitution character, AWK or SED?

Hi Gurus, I am working with a korn shell script. I should replace in a very great file the character ";" with a space. Example: 2750;~ 2734;~ 2778;~ 2751;~ 2751;~ 2752;~ what the fastest method is? Sed? Awk? Speed is dead main point, Seen the dimensions of the files Thanks (6 Replies)
Discussion started by: GERMANICO
6 Replies

6. Shell Programming and Scripting

In Sed how can I replace starting from the 7th character to the 15th character.

Hi All, Was wondering how I can do the following.... I have a String as follows "ACCTRL000005022RRWDKKEEDKDD...." This string can be in a file called tail.out or in a Variable called $VAR2 Now I have another variable called $VAR1="000004785" (9 bytes long), I need the content of... (5 Replies)
Discussion started by: mohullah
5 Replies

7. UNIX for Dummies Questions & Answers

Help with sed substitution

I'm a noob to unix, and I have a line of data like the following: title=Boston|tcolor=green|desc=Large city in New England|url=www.boston.com Is there a way to change a field value with sed substitution? (i.e. change tcolor=green to tcolor=blue) I figured out: sed... (19 Replies)
Discussion started by: stabby
19 Replies

8. Shell Programming and Scripting

sed substitution

Using sed I'm trying to replace 'string' with ']' while retaining case and ignoring words with 'string' in it along with additional characters like 'strings' and those which already contain the ] wrapper. I'm hoping to do it with sed and the right expression, if possible. Example: Apple... (2 Replies)
Discussion started by: tom.lee
2 Replies

9. Shell Programming and Scripting

sed global substitution for ' character

Hi all, I have a text file containing sql commands. I want to use sed to replace the " character with the ' character. But when i run the command below it just replaces it with a space? Do i have the escape the ' character if i want to use it? cat sql.txt update customer set custid =... (1 Reply)
Discussion started by: borderblaster
1 Replies

10. Shell Programming and Scripting

character substitution

Hi , I have a problem , I need to devlope a script where in the user inputs file name , line number , and character position , and a substitution variable , the character at that character position should be substituted by the substitution value for ex say i have a file abc.txt which... (3 Replies)
Discussion started by: viv1
3 Replies
Login or Register to Ask a Question