5

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.

Rohit Gupta
  • 340
  • 2
  • 3
  • 11
Rizwan.A
  • 53
  • 5

1 Answers1

7

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
Dan
  • 12,494
  • 7
  • 70
  • 94
Raffa
  • 24,905
  • 3
  • 35
  • 79
  • this result in "tvg-name="gama1 , require result tvg-name="gama1" – Rizwan.A Apr 04 '23 at 23:09
  • @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. – Raffa Apr 04 '23 at 23:20
  • 2
    @Raffa it's more likely that the input file has CRLF line endings I think – steeldriver Apr 04 '23 at 23:30
  • 1
    @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 – Raffa Apr 04 '23 at 23:43