Quantcast
Channel: How can I reverse the order of lines in a file? - Stack Overflow
Viewing all articles
Browse latest Browse all 26

Answer by Yauhen Yakimovich for How can I reverse the order of lines in a file?

$
0
0

EDITthe following generates a randomly sorted list of numbers from 1 to 10:

seq 1 10 | sort -R | tee /tmp/lst |cat <(cat /tmp/lst) <(echo '-------') **...**

where dots are replaced with actual command which reverses the list

tac

seq 1 10 | sort -R | tee /tmp/lst |cat <(cat /tmp/lst) <(echo '-------') \<(tac)

python: using [::-1] on sys.stdin

seq 1 10 | sort -R | tee /tmp/lst |cat <(cat /tmp/lst) <(echo '-------') \<(python -c "import sys; print(''.join(([line for line in sys.stdin])[::-1]))")

Viewing all articles
Browse latest Browse all 26

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>