I bought this to connect my TV to my soundbar. Does the cable go into the "audio out" on the TV and into the "line in" on the soundbar? I found that I needed a digital coaxial cable to come out of the digital coaxial out on the back of my tv. Then I needed an adapter with the audio digital coaxial connection on one end, and the SPDIF connection on the other. I connected a toslink SPDIF from this end of the adapter to the SPDIF connection on the sound bar. Perfect! The sound is great, everything is going through the TV, not a blue ray player or an xbox. It's important to turn off the sound on the TV. Now I just have to keep track of the soundbar remote--it's pretty small but it's the only way I can adjust the volume.
If you would state which model TV and Soundbar you have then I can be more specific with a response.
Yes you would need to connect to an OUTPUT on the TV and an INPUT on the Soundbar. I assume that your TV does have an OPTICAL OUT also known as an SPDIF (Optical) connector. If yours does, then you would connect the cable here and plug the other end to a similar looking OPTICAL INPUT connector on the Soundbar. Please note that you would normally have to go into the TV set up to specify that you are trying to output audio via this connector as opposed to one of the other available options. Please check this if there is no sound on the Soundbar before you condemn the effort.
If you do not have Optical connectors on BOTH ends, then you would need to look for one common connector on both ends and get the corresponding cable. RCA connectors (the usual red and white end cables), are the most common, though not best quality.
This cable is fiber optical, so it will connect to a digital optical output on the TV, and a digital optical audio input on the soundbar, provided the soundbar has such an input. "Line in" is generally an analog input, either RCA or 3.5mm mini jack, so "line in" probably isn't going to work with this cable.