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
  • 77,877
  • 8
  • 106
  • 148
CharlieB
  • 19
  • 1
  • 6
  • 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 Quénot
  • 173,512
  • 41
  • 224
  • 223
0

This might work for you:

sed -n $VAR's/$/,nosuid/' > to_file
potong
  • 55,640
  • 6
  • 51
  • 83