little sed help
am 03.01.2008 18:42:54 von prabatoI 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 help.
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 help.
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
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.
On 2008-01-03, prabato@gmail.com
>
>
> 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 help.
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 help.
This would do, provided the content of $shellVar
won't hide bovver chars:
sed -n "/130/{g;s/^$/$shellVar/};p"
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 help.
Assuming you don't really NEED to use sed:
awk -v var="$shell_var" '{print NR==130?var:$0}' file
Ed.
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 help.
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