|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
I need sed to delete line 130 and then replace it with the $shell_var
sed -e '130s/ d' ^^^ doesn't work sed -e '130i/$shell_var/' ^^^ doesn't work please . |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On Thu, 3 Jan 2008 09:42:54 -0800 (PST), prabato@gmail.com wrote:
> I need sed to delete line 130 and then replace it with the $shell_var > > sed -e '130s/ d' > ^^^ doesn't work > > sed -e '130i/$shell_var/' > ^^^ doesn't work sed "130s/.*/$shell_var/" assuming $shell_var doesn't contain any /, \, & or newline character. awk -v repl="$shell_var" 'NR == 130 {$0 = repl} {print}' assuming $shell_var doesn contain \ characters. Or sed "130!b i\\ $shell_var d" assuming $shell_var doesn't contain \ or newline characters. -- Stephane |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
prabato@gmail.com wrote:
> I need sed to delete line 130 and then replace it with the $shell_var > > sed -e '130s/ d' > ^^^ doesn't work > > sed -e '130i/$shell_var/' > ^^^ doesn't work sed "130{i $shell_var d}" filename -- Best regards | Be nice to America or they'll bring democracy to Cyrus | your country. |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On 2008-01-03, prabato@gmail.com <prabato@gmail.com> wrote:
> > > I need sed to delete line 130 and then replace it with the $shell_var > > sed -e '130s/ d' > ^^^ doesn't work What are you trying to do here? The s command requires three separators: s/pattern/replacement/ > > sed -e '130i/$shell_var/' > ^^^ doesn't work > Shell variables aren't substituted inside single quotes. Use double quotes, if that's what you want. > please . |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
On Thu, 03 Jan 2008 09:42:54 -0800, prabato wrote:
> I need sed to delete line 130 and then replace it with the $shell_var > > sed -e '130s/ d' > ^^^ doesn't work > > sed -e '130i/$shell_var/' > ^^^ doesn't work > > please . This would do, provided the content of $shellVar won't hide bovver chars: sed -n "/130/{g;s/^$/$shellVar/} " |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
On 1/3/2008 11:42 AM, prabato@gmail.com wrote: > I need sed to delete line 130 and then replace it with the $shell_var > > sed -e '130s/ d' > ^^^ doesn't work > > sed -e '130i/$shell_var/' > ^^^ doesn't work > > please . Assuming you don't really NEED to use sed: awk -v var="$shell_var" '{print NR==130?var:$0}' file Ed. |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
On Jan 4, 1:42 am, prab...@gmail.com wrote:
> I need sed to delete line 130 and then replace it with the $shell_var > > sed -e '130s/ d' > ^^^ doesn't work > > sed -e '130i/$shell_var/' > ^^^ doesn't work > > please . use this, for very large files #!/bin/sh head -129 file > outfile echo "my string" >> outfile tail +131 file >> outfile #or more +131 file >> outfile |
|
![]() |
| Outils de la discussion | |
|
|