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.

1
  • question edited as requested. please
    – Rizwan.A
    Apr 4, 2023 at 22:28

1 Answer 1

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
4
  • this result in "tvg-name="gama1 , require result tvg-name="gama1"
    – Rizwan.A
    Apr 4, 2023 at 23:09
  • @Rizwan.A Check your current locale 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 4, 2023 at 23:20
  • 2
    @Raffa it's more likely that the input file has CRLF line endings I think Apr 4, 2023 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 askubuntu.com/q/803162 ... Thanks @steeldriver
    – Raffa
    Apr 4, 2023 at 23:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .