For example i have a file:
$ cat file
i am the first example.
i am the second line.
i do a question about a file.
and i need:
tldr;
$ awk '{print $NF}' file.txt | paste -sd, | sed 's/,/, /g'
For a file like this
$ cat file.txt
The quick brown fox
jumps over
the lazy dog.
the given command will print
fox, over, dog.
How it works:
awk '{print $NF}' : prints the last field of every linepaste -sd, : reads stdin serially (-s, one file at a time) and writes fields comma-delimited (-d,)sed 's/,/, /g' : substitutes "," with ", " globally (for all instances)References: