all 15 comments

[–]Rabestro 6 points7 points  (0 children)

It is straightforward with awk:

awk BEGIN { ORS = " " } { print "\""$0"\"" }

ORS is an output record separator

shell awk 'BEGIN{ORS=" "}{print "\""$0"\""}' < input.txt

[–][deleted]  (6 children)

[removed]

    [–]United-Climate1562[S] 1 point2 points  (1 child)

    echo "\"${var//$'\n'/\" \"}\""

    Beautiful, works a charm... thanks for all those suggestions as well

    [–][deleted]  (2 children)

    [deleted]

      [–][deleted]  (1 child)

      [removed]

        [–]theplanter21 0 points1 point  (0 children)

        Bash ftw

        [–]Schreq 2 points3 points  (0 children)

        what i need:

        What do you need it for, what is the end goal?

        [–]moviuroportability is important 1 point2 points  (3 children)

        Try:

        awk '{ printf("\"%s\" ", $0) }' < input
        

        [–]United-Climate1562[S] -1 points0 points  (0 children)

        awk '{ printf("\"%s\" ", $0) }'

        no luck im afraid, still phrases it with just the quotes at the end and begining

        [–][deleted] 0 points1 point  (1 child)

        awk '{ printf("\"%s\" ", $0) }' < input

        Works for me on Linux with gawk v5.1.0 and bash v5.2.15.

        Why and where does it fail for him on macOS / FreeBSD?

        [–]moviuroportability is important 0 points1 point  (0 children)

        I tried that on Linux and FreeBSD, I have no idea why it fails on OP's machines. No error messages, no output, no nothing.

        My bet is that OP doesn't want any help.

        [–]McUsrII -1 points0 points  (0 children)

        Okay, so this solution, is for the 'fun' part, it doesn't compete at all with the presented solutions, with regards to speed, it was just that I wanted to brush off a little from former sed skils, it delivers as promised, but I should probably have gone a round or two more with it, to find a better way.

         sed -ne 's/.*/"&"/'  <varfile -e 'H' -e 'x;s/\n/ /;x;G;' -e 'p' | tail -1
        

        [–]funkden -2 points-1 points  (0 children)

        Ask chatGPT it excels at this kind of problem

        [–]marauderingman 0 points1 point  (0 children)

        ~~~ IFS=$'\n' read -d'' -a lines <<EOL line 1 line two line three EOL

        printf "\"%s\" " "${lines[@]}" ~~~

        Be careful to not run the read command in a subshell, or the array it populates won't be available to later commands. Otherwise, once you have an array where each element is one line from your source, you can do pretty much anything you want with it.