Score:5

combine single text with multiple lines of file

mp flag

I am trying to combine work tvg-name with multiple lines of a file

tr '\n' '~' < file1.txt | sed s/~/tvg-name/g

results in only first single-line print

tvg-namegama1

my file1.txt has more than 50 lines e.g.

gama1
beta2
tera3

and so on more than 50 lines

required output

tvg-name="gama1"
tvg-name="beta2"

and so on till the file ends.

Rizwan.A avatar
mp flag
question edited as requested. please
Score:7
jp flag

You can use sed alone, like so:

sed 's/.*/tvg-name="&"/' file1.txt

That will prepend tvg-name=" and append " to each line in your file.

That can also be done with awk, like so:

awk '{printf "tvg-name=\"%s\"\n", $0}' file1.txt

Or with pure bash, like so:

while IFS= read -r l; do printf 'tvg-name="%s"\n' "$l"; done < file1.txt
Rizwan.A avatar
mp flag
this result in "tvg-name="gama1 , require result tvg-name="gama1"
Raffa avatar
jp flag
@Rizwan.A Check your current `locale` https://askubuntu.com/q/89976 … You might need to change it to some standard English .,. The effect you describe can be as a result of e.g. right to left locale … The above `sed` command can’t do that … You can pipe the output to a file and check.
hr flag
@Raffa it's more likely that the input file has CRLF line endings I think
Raffa avatar
jp flag
@Rizwan.A If you have edited your file on Windows at some point, then your file could have Windows style carriage return line endings instead of the Unix/Linux newline and that could also result in mangling the output ... Check your file withe the `file` command like so `file file1.txt` and see if it prints `CRLF line endings` ... If so then you need to sanitize your file first https://askubuntu.com/q/803162 ... Thanks @steeldriver
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.