Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

find and replace character

Status
Not open for further replies.

sachrath

Programmer
May 21, 2004
17
CH
I am having a huge file .
I need to find a chaacter only in the last line and replace it with another characted
I am not a UNIX expert , so would like do it with SED one liner .
Any help is appreciated

Thx
Sachin Rath
 
something like this ?
sed '$s!x!y!' /path/to/input >output

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
To change A to B in the last line of a file, try

sed '$s/A/B/' infile > oufile

CaKiwi
 
My file name is x.parm

and the last line number of my file is 37 & I need to replace 90 with 91 so I tried

sed '37s/90/91/' x.parm > x.parm .

Where am I commiting a mistake ???

Sachin
 
x.parm > x.parm
The shell redirection will erase your file before sed read it.
You may try this:
sed '$s/90/91/' x.parm > x.$$ && mv x.$$ x.parm

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
You can't create the output file with the same name as the input file. Try

sed '$s/90/91/' x.parm > tmp.parm && mv tmp.parm x.parm

CaKiwi
 
Thx guys ...it worked .

Is this advisable to find & replace in the same way for very huge files as well.

Thx
Sachin Rath
 
You may have to consider df to ensure enough place is free in the file system.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Yeah , I had checked the space which looks enough .

Now I know how to go to a line in a file to follow up with further operations .

Thx again
Chao
Sachin

 
If you have perl then you can edit files in place...

eg.1:[tt] perl -pi -e '$.==37 && s/90/91/' x.parm[/tt]
eg.2:[tt] perl -pi -e 'eof && s/90/91/' x.parm[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top