Operating System - HP-UX
1849810 Members
1901 Online
104044 Solutions
New Discussion

Re: change string in a file

 
SOLVED
Go to solution
ust3
Regular Advisor

change string in a file

I have a file , the content is as below , all lines ended with .txt , I want to change all lines to .prn , I try to use the script (sed -e "s/.txt/.prn/" file > new_file) , but not work , can advise what can I do ? thx

$vi file
abc.txt
abd.txt
abe.txt
abf.txt
abg.txt
3 REPLIES 3
Dennis Handly
Acclaimed Contributor
Solution

Re: change string in a file

What do you mean "but not work"?
It seems your sed command should work fine. All I'd do is make sure you quote the ".":
$ sed -e "s/\.txt/.prn/" file > new_file
AwadheshPandey
Honored Contributor

Re: change string in a file

u can use vi also for same.

%s/txt/prn/g

http://sunsite.uakom.sk/sunworldonline/swol-11-1997/swol-11-unix101.html
It's kind of fun to do the impossible
Dennis Handly
Acclaimed Contributor

Re: change string in a file

>Awadhesh: you can use vi also for same.
%s/txt/prn/g

It would probably be safer to use:
%s/\.txt$/.prn/

Only get the extensions on the end of lines.