Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I replace a specific line by line number in a text file?

Tags:

linux

I have a 2GB text file on my linux box that I'm trying to import into my database.

The problem I'm having is that the script that is processing this rdf file is choking on one line:

mismatched tag at line 25462599, column 2, byte 1455502679:
<link r:resource="http://www.epuron.de/"/>
<link r:resource="http://www.oekoworld.com/"/>
</Topic>
=^

I want to replace the </Topic> with </Line>. I can't do a search/replace on all lines but I do have the line number so I'm hoping theres some easy way to just replace that one line with the new text.

Any ideas/suggestions?

like image 702
GeoffreyF67 Avatar asked Mar 31 '09 23:03

GeoffreyF67


2 Answers

sed -i yourfile.xml -e '25462599s!</Topic>!</Line>!'
like image 141
chaos Avatar answered Oct 10 '22 08:10

chaos


sed -i '25462599 s|</Topic>|</Line>|' nameoffile.txt
like image 38
David Z Avatar answered Oct 10 '22 09:10

David Z