0

I have a file that I need to append to certain lines.

I can get the line numbers and have been able to use sed to print the entry but not to append the entry.

All I need to do is something like

sed -n '$VAR s/$/,nosuid/' > to_file

Just can not get the syntax down.

Thank you.

Etan Reisner
  • 73,512
  • 8
  • 94
  • 138
CharlieB
  • 19
  • 1
  • 5
  • Shell variables do not expand in single quotes. Assuming `$VAR` is a shell variable you need to use double quotes around it. `"$VAR s/$/,nosuid/"` or `"$VAR"' s/$/,nosuid/'` or similar. – Etan Reisner Dec 01 '14 at 18:01
  • possible duplicate of [Expansion of variable inside single quotes in a command in bash shell script](http://stackoverflow.com/questions/13799789/expansion-of-variable-inside-single-quotes-in-a-command-in-bash-shell-script) – Etan Reisner Dec 01 '14 at 18:03

2 Answers2

0

Try doing this :

 sed "$VAR s/$/,nosuid/" > to_file

Like Etan Reisner said in the comments, the quotes should be double quotes.

Gilles Quenot
  • 154,891
  • 35
  • 213
  • 206
0

This might work for you:

sed -n $VAR's/$/,nosuid/' > to_file
potong
  • 51,370
  • 6
  • 49
  • 80