Replace line X with String Y using sed/awk - shell
This is a discussion on Replace line X with String Y using sed/awk - shell ; Hi I have about 30 files, that are just a list of options to run a unix program. I need to find a way to replace a certain line number with a different string I specify. The data in the ...
| | LinkBack | Thread Tools | Display Modes |
|
#1
| |||
| |||
| I have about 30 files, that are just a list of options to run a unix program. I need to find a way to replace a certain line number with a different string I specify. The data in the files I am looking to replace are dates. Here is an example: file1.txt: Line 1 : Hello Line 2 : Goodbye Line 3 : 10102007 Line 4 : 10312007 For example, say line 3 I want to replace that date of 10102007 with 11012007. But I do not want to have to reference the value of the file, for example doing a : sed 's/10102007/11012007/' ... Rather specify the whole line to replace. How can I do that? Thanks! |
|
#2
| |||
| |||
|
thesoulcrusher wrote: > > I need to find a way to replace a certain line number with a different > string I specify. The data in the files I am looking to replace are > dates. > > Here is an example: > > file1.txt: > > Line 1 : Hello > Line 2 : Goodbye > Line 3 : 10102007 > Line 4 : 10312007 > > For example, say line 3 I want to replace that date of 10102007 with > 11012007. sed "3s/10102007/11012007/" file1.txt > But I do not want to have to reference the value of the file, for > example doing a : sed 's/10102007/11012007/' ... Rather specify the > whole line to replace. -- Best regards | "The only way to really learn scripting is to write Cyrus | scripts." -- Advanced Bash-Scripting Guide |
|
#3
| |||
| |||
|
thesoulcrusher wrote: > Hi > > I have about 30 files, that are just a list of options to run a unix > program. > > I need to find a way to replace a certain line number with a different > string I specify. The data in the files I am looking to replace are > dates. > > Here is an example: > > file1.txt: > > Line 1 : Hello > Line 2 : Goodbye > Line 3 : 10102007 > Line 4 : 10312007 > > For example, say line 3 I want to replace that date of 10102007 with > 11012007. > > But I do not want to have to reference the value of the file, for > example doing a : sed 's/10102007/11012007/' ... Rather specify the > whole line to replace. > > How can I do that? > > > Thanks! > awk 'NR==3{$0=11012007}1' file Ed. |
|
#4
| |||
| |||
|
thesoulcrusher wrote: > Hi > > I have about 30 files, that are just a list of options to run a unix > program. > > I need to find a way to replace a certain line number with a different > string I specify. The data in the files I am looking to replace are > dates. > > Here is an example: > > file1.txt: > > Line 1 : Hello > Line 2 : Goodbye > Line 3 : 10102007 > Line 4 : 10312007 > > For example, say line 3 I want to replace that date of 10102007 with > 11012007. > > But I do not want to have to reference the value of the file, for > example doing a : sed 's/10102007/11012007/' ... Rather specify the > whole line to replace. > > How can I do that? > > sed '3s/ : .*/ : 11012007/' awk -v v=11012007 'BEGIN{FS=OFS=" : "} NR==3{$2=v} 1' -- Michael Tosch @ hp : com |
« Previous Thread
|
Next Thread »
| Thread Tools | |
| Display Modes | |
| |
LinkBack to this Thread: http://dbaspot.com/forums/shell/270141-replace-line-x-string-y-using-sed-awk.html | ||||
| Posted By | For | Type | Date | |
| Replace line X with String Y using sed : Linux T&T | This thread | Pingback | 11-11-2008 04:37 AM | |
All times are GMT -4. The time now is 05:44 PM.

Linear Mode