I am new to UNIX and was going through a script file and came accross a snippet.
I tried to analyze the snippet. I read a bit about the
'sed - stream editor'
echo ABCDEFGHIJK KLMJN | \
sed -e "1,\$s/ *$/^\"`echo $ID`\"/" \
You should look at it part for part.
sed -e "1,\$s/ *$/^\"`echo $ID`\"/" | | | | 1 2 3
You want to only work on specific lines. For that example start with the first line and end with the last. In this case it isn't needed to write that in this way. So
sed -e "s/ *$/^\"$(echo $ID)\"/"
does exactly the same.
Here comes the replace command. In this case you replace zero or more spaces between the last non-space and the line ending. If you want to find out more about this I suggest googling for
The backtick (``) is actually a 'shellism'. It causes the shell to execute the command before replacing. For a more readable way you should use
$(echo $ID). After that you replace the regex from 2. with the result of this, which will be '^"101"'
And after that the result is