tags:

views:

146

answers:

2

Hi Guys,

This is probably a simple one to answer, but I'm stuck, so here goes.

sed '3d' filename    # (or something like that)

I'm having trouble trying to use a $VARIABLE instead of the number.

Anyone know how to get this to work, or any alternative options?

Regards

Paul

+6  A: 

Did you mean this:

bash$ VARIABLE=3
bash$ sed "${VARIABLE}d" filename

(I'm not sure if this is correct use of the sed command, I just know that's how you would use a variable next to a letter in bash syntax.)

too much php
+1  A: 
$ variable=3
$ awk -vvar="$variable" 'NR!=var' file

using the shell(bash)

variable=3
i=1
while read -r line
do
  [ "$i" -ne "$variable" ] && echo "$line"
  ((i++))
done <"file" > newfile
ghostdog74
+1. alternate variable assignment for `awk` (POSIX IIRC): `awk 'NR!=var' vvar="$variable" file` :)
vladr
the only problem with that alternate syntax is that if `vvar` will not have a value inside BEGIN block.
ghostdog74