Reputation: 10093
I have a file which I must iterate through several times, running it with python each time. How can I remove or add characters from specific lines in shell?
for an example file ex.file,
$ cat ex.file
stuff
more stuff
more stuff
more stuff
#<- remove this character
<-add a pund sign here
more stuff
more stuff
my desired output would be:
$ cat ex.file
stuff
more stuff
more stuff
more stuff
<- remove this character
#<-add a pund sign here
more stuff
more stuff
Upvotes: 5
Views: 3924
Reputation: 18411
Oneliner awk version to remove # from 5th line and add # to 6th line.
awk 'NR==5 {sub(/^#/,"") } NR==6 { sub(/^/,"#")}1' infile
Upvotes: 2
Reputation: 249502
To add a # at the start of line 6:
sed '6 s/^/#/' ex.file
To remove the leading # from line 5:
sed '5 s/^#//' ex.file
Upvotes: 7