↧
Answer by Jessica Baker-seuk for How can I reverse the order of lines in a file?
Not sure if I missed something.How about pipe into sorti.e.cat file | sort -rSorry if I missed the point of this question.I often use this to scan syslogs.In linux :watch " tail /var/log/syslog | sort...
View ArticleAnswer by Georg Fischer for How can I reverse the order of lines in a file?
You may use Perl on the commandline:perl -e 'my @b=(); while(<>) {push(@b, $_);}; print join("", reverse(@b));' orig > rev
View ArticleAnswer by youkaichao for How can I reverse the order of lines in a file?
It happens to me that I want to get the last n lines of a very large text file efficiently.The first thing I tried is tail -n 10000000 file.txt > ans.txt, but I found it very slow, for tail has to...
View ArticleAnswer by driver for How can I reverse the order of lines in a file?
I see lots of interesting ideas. But try my idea. Pipe your text into this: rev | tr '\n''~' | rev | tr '~''\n'which assumes that the character '~' is not in the file. This should work on every UNIX...
View ArticleAnswer by Mark Booth for How can I reverse the order of lines in a file?
If you want to modify the file in place, you can runsed -i '1!G;h;$!d' filenameThis removes the need to create a temporary file and then delete or rename the original and has the same result. For...
View ArticleAnswer by Marius Hofert for How can I reverse the order of lines in a file?
For Emacs users: C-x h (select the whole file) and then M-x reverse-region. Also works for only selecting parts or the lines and reverting those.
View ArticleAnswer by Yakir GIladi Edry for How can I reverse the order of lines in a file?
at the end of your command put:| tactac does exactly what you're asking for, it "Write each FILE to standard output, last line first."tac is the opposite of cat :-).
View ArticleAnswer by Bohdan for How can I reverse the order of lines in a file?
tail -r works in most Linux and MacOS systemsseq 1 20 | tail -r
View ArticleAnswer by dosentmatter for How can I reverse the order of lines in a file?
You can do it with vimstdin and stdout. You can also use ex to be POSIX compliant. vim is just the visual mode for ex. In fact, you can use ex with vim -e or vim -E (improved ex mode).vim is useful...
View ArticleAnswer by R. Kumar for How can I reverse the order of lines in a file?
This will work on both BSD and GNU.awk '{arr[i++]=$0} END {while (i>0) print arr[--i] }' filename
View ArticleAnswer by jins for How can I reverse the order of lines in a file?
tac <file_name>example:$ cat file1.txt12345$ tac file1.txt54321
View ArticleAnswer by lacostenycoder for How can I reverse the order of lines in a file?
For cross OS (i.e. OSX, Linux) solution that may use tac inside a shell script use homebrew as others have mentioned above, then just alias tac like so:Install libFor MacOSbrew install coreutilsFor...
View ArticleAnswer by ITNM for How can I reverse the order of lines in a file?
Best solution:tail -n20 file.txt | tac
View ArticleAnswer by Yoker Rekoy for How can I reverse the order of lines in a file?
sort -r < filenameorrev < filename
View ArticleAnswer by Yekatandilburg for How can I reverse the order of lines in a file?
The simplest method is using the tac command. tac is cat's inverse.Example:$ cat order.txtroger shah armin van buurenfpga vhdl arduino c++ java gridgain$ tac order.txt > inverted_file.txt$ cat...
View ArticleAnswer by konsolebox for How can I reverse the order of lines in a file?
Just Bash :) (4.0+)function print_reversed { local lines i readarray -t lines for (( i = ${#lines[@]}; i--; )); do printf '%s\n'"${lines[i]}" done}print_reversed < file
View ArticleAnswer by Yauhen Yakimovich for How can I reverse the order of lines in a file?
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...
View ArticleAnswer by DigitalRoss for How can I reverse the order of lines in a file?
$ (tac 2> /dev/null || tail -r)Try tac, which works on Linux, and if that doesn't work use tail -r, which works on BSD and OSX.
View ArticleAnswer by Tim Menzies for How can I reverse the order of lines in a file?
I really like the "tail -r" answer, but my favorite gawk answer is....gawk '{ L[n++] = $0 } END { while(n--) print L[n] }' file
View ArticleAnswer by DerMike for How can I reverse the order of lines in a file?
If you happen to be in vim use:g/^/m0Explanation from @Ronopolis below:g means "do this globally.^ means "the beginning of a line".m means "move the line to a new line number. 0 is which line to move...
View Article
More Pages to Explore .....