here is an example of how you could do it:
% cat subject.txt
Studid StudName Asp.Net DBMS Unix
1 Ani 75 62 80
2 George 90 95 82
3 Jake 45 30 40
4 Dennie 89 92 90
%
% my_var="R2D2"
%
% sed "s/$/${my_var}/" subject.txt
Studid StudName Asp.Net DBMS UnixR2D2
1 Ani 75 62 80R2D2
2 George 90 95 82R2D2
3 Jake 45 30 40R2D2
4 Dennie 89 92 90R2D2
Explanation
The tricky thing about this sed
expression, is why don't I need to reinsert the $
newline in the replace part of the substitution?.
I believe this is because when sed
loads each line into the pattern space it removes the newline, then after all pattern space operations, it then re-attaches a newline to the contents of the pattern space then prints the pattern space, so I guess the newline is a kind of a "freebie" here.
Then you might ask the question, how does the first $
match if the pattern space has no newline in it ? -- if I had to guess, I might say , sed
just knows what you mean when you use the $
meta character, but that is just a guess.