Create a file a.tsv with two lines
echo aa bbb ccc ddd >a.tsv
echo xxxxxxxaa bbb ccc ddd >>a.tsv
replace each line with dynamic generated string in a shell script a.sh
#!/bin/bash
#get line number
l1=$1
l2=$(expr $1 + 1)
#input file name
fn=$2
#get string in l1 line
vv="{${l1},${l1}p;${l2}q}"
v1=$(sed -n ${vv} $fn )
echo $v1
#cut off 6 chars from the end of string v1
v2=${v1::-6}
echo $v2
#replace l1 line v1 with new line v2
vb="{s|${v1}|${v2}|g }"
echo $vb
sed -i -r '$vb' $fn
when I run it as:
./a.sh 1 a.tsv
But I get those output:
What is wrong?
aa bbb ccc ddd
aa bbb c
{s|aa bbb ccc ddd|aa bbb c|g }
sed: -e expression #1, char 3: expected newer version of sed