Skip to main content
added 178 characters in body
Source Link

For Line parsing , you should mention the line number preceding the command 's'

$ echo "this is line 1
this is line 2
this is line 3
this is line 4
this is line 5" | sed -e '2s/line/LINUX/'
this is line 1
this is LINUX 2
this is line 3
this is line 4
this is line 5

So, for you the command is :

sed -e '2s/line/LINUX/' mytextfile

And yes , if regardless of line number , if you want to just replace the 2nd occurrence in the whole file , pLumo's answer is right.

sed -z 's/line/LINUX/2' mytextfile

For Line parsing , you should mention the line number preceding the command 's'

$ echo "this is line 1
this is line 2
this is line 3
this is line 4
this is line 5" | sed -e '2s/line/LINUX/'
this is line 1
this is LINUX 2
this is line 3
this is line 4
this is line 5

So, for you the command is :

sed -e '2s/line/LINUX/' mytextfile

For Line parsing , you should mention the line number preceding the command 's'

$ echo "this is line 1
this is line 2
this is line 3
this is line 4
this is line 5" | sed -e '2s/line/LINUX/'
this is line 1
this is LINUX 2
this is line 3
this is line 4
this is line 5

So, for you the command is :

sed -e '2s/line/LINUX/' mytextfile

And yes , if regardless of line number , if you want to just replace the 2nd occurrence in the whole file , pLumo's answer is right.

sed -z 's/line/LINUX/2' mytextfile
Source Link

For Line parsing , you should mention the line number preceding the command 's'

$ echo "this is line 1
this is line 2
this is line 3
this is line 4
this is line 5" | sed -e '2s/line/LINUX/'
this is line 1
this is LINUX 2
this is line 3
this is line 4
this is line 5

So, for you the command is :

sed -e '2s/line/LINUX/' mytextfile