I am currently trying to replace lines in the following file:
Music_location = /home/music
Music_location = /home/music
Pictures = /home/pictures
How do I only replace the first "/home/music" without saying what line it is on? Thanks!
I am currently trying to replace lines in the following file:
Music_location = /home/music
Music_location = /home/music
Pictures = /home/pictures
How do I only replace the first "/home/music" without saying what line it is on? Thanks!
Using awk you can do this:
awk '!p{sub(/\/home\/music/, "/foo/bar"); p=1} 1' file
Music_location = /foo/bar
Music_location = /home/music
Pictures = /home/pictures
In sed:
sed '0,/home\/music/s_/home/music_/foo/bar_' foo.txt
This starts at line 0, stops when it finds /home/music, and then replaces the /home/music with /foo/bar. In the "s_/home/music_/foo/bar_" part, I have changed the normal delimiter, a slash, to an underscore, so that I may use slashes in my regular expression.