Sample Header Ad - 728x90

Unix & Linux Stack Exchange

Q&A for users of Linux, FreeBSD and other Unix-like operating systems

Latest Questions

4 votes
2 answers
948 views
tac-command is it a bug or a misinterpretation of the manual?
I needed to reverse the order of blank-separated words. GNU `tac` comes to mind and has an `-s`-option which lets you set the separator: -s, --separator=STRING use STRING as the separator instead of newline So I tried: $ echo -e A B C D E F | tac -s' ';echo F E D C B A $ echo -e A B C D E F | tac -s...
I needed to reverse the order of blank-separated words. GNU tac comes to mind and has an -s-option which lets you set the separator: -s, --separator=STRING use STRING as the separator instead of newline So I tried: $ echo -e A B C D E F | tac -s' ';echo F E D C B A $ echo -e A B C D E F | tac -s' ' | tr ' ' '-';echo F E-D-C-B-A- $ where the final echo is to have the next prompt on a separate line and the tr ' ' '-' is to see any invisible blanks at the end of the output lines. What irritates me is the newline after the "F" in the output. Looks like a bug to me, is it? While writing this question and looking at the suggestions for similar questions (a **very good** feature), I saw https://unix.stackexchange.com/q/598611/268339 and learned about rev, which is exactly what I wanted. Still, for tac, is it a bug or a feature?
Gyro Gearloose (455 rep)
Jul 23, 2025, 09:17 AM • Last activity: Jul 29, 2025, 05:52 PM
5 votes
4 answers
2078 views
Reversing a file line-wise and character-wise
Input: ``` hello enrico ``` output: ``` ocirne olleh ``` To do this, I can simply `tac` a file and pipe the output to `rev` (or the other way around), so one function that does the job is just this: ```bash revtac() { tac "$@" | rev; } ``` Is there a built-in function for the job? I suspect that thi...
Input:
hello
enrico
output:
ocirne
olleh
To do this, I can simply tac a file and pipe the output to rev (or the other way around), so one function that does the job is just this:
revtac() { tac "$@" | rev; }
Is there a built-in function for the job? I suspect that this could potentially break something, as it would reverse ` and ` on Windows-generated files, but I'm still interested.
Enlico (2258 rep)
Jul 15, 2020, 12:34 PM • Last activity: Sep 15, 2024, 05:27 AM
1 votes
3 answers
659 views
How to concatenate files in reverse order
I am looking to concatenate a list of files in a directory in the reverse order that they appear in the list. This is different from `tac` as `tac` will concatenate the files with reversed line order. Basically I have a folder with 3 files, `file1`, `file2` and `file3`. `cat f* > newfile` will merge...
I am looking to concatenate a list of files in a directory in the reverse order that they appear in the list. This is different from tac as tac will concatenate the files with reversed line order. Basically I have a folder with 3 files, file1, file2 and file3. cat f* > newfile will merge these files like so: file1 file2 file3 However, I want to merge the files like this file3 file2 file1 whilst maintaining the correct line order.
sarahParker (11 rep)
Apr 26, 2022, 05:26 PM • Last activity: Apr 26, 2022, 06:38 PM
7 votes
2 answers
2867 views
reverse file character by character using tac
I want to use the `tac`to reverse a text file character by character. On the info page for coreutils I found an example saying: #Reverse a file character by character `tac -r -s 'x\|[^x]'` However running `tac -r -s` seems to open standard input instead of printing the file. What does `'x\|[^x]'` me...
I want to use the tacto reverse a text file character by character. On the info page for coreutils I found an example saying: #Reverse a file character by character tac -r -s 'x\|[^x]' However running tac -r -s seems to open standard input instead of printing the file. What does 'x\|[^x]' mean and what should I be doing? I also noted that the output for tac [file] and tac -r [file] are same and they're the same as cat [file]. Still can't figure out char by char reverse.
Weezy (679 rep)
May 28, 2018, 06:29 AM • Last activity: Dec 13, 2019, 09:42 PM
12 votes
2 answers
1140 views
Explanation of tac --before
> -b, --before > > The separator is attached to the beginning of the record that it > precedes in the file. And I can't understand the following output: $ echo -e "Hello\nNew\nWorld\n!" > file $ tac file ! World New Hello $ tac -b file ! World NewHello Why there is no newline between `New` and `Hell...
> -b, --before > > The separator is attached to the beginning of the record that it > precedes in the file. And I can't understand the following output: $ echo -e "Hello\nNew\nWorld\n!" > file $ tac file ! World New Hello $ tac -b file ! World NewHello Why there is no newline between New and Hello?
SantaXL (375 rep)
Oct 21, 2019, 06:18 PM • Last activity: Oct 23, 2019, 07:54 AM
1 votes
1 answers
312 views
Usage of readarray and tac
I have a file containing "lines" of text, for now only two lines. I need to create a reversed array of these lines - FIFO style. Using "readarray" in this fashion works fine: readarray -t FileArray < "$PWD$DEBUG_DIR$DEBUG_MENU" When I attempt to "reverse" the file I get gibberish: readarray -t FileA...
I have a file containing "lines" of text, for now only two lines. I need to create a reversed array of these lines - FIFO style. Using "readarray" in this fashion works fine: readarray -t FileArray < "$PWD$DEBUG_DIR$DEBUG_MENU" When I attempt to "reverse" the file I get gibberish: readarray -t FileArray < tac "$PWD$DEBUG_DIR$DEBUG_MENU" I am still learning about substitution and it is obvious I am not using the tac command correctly. I did try different "syntax" without success.
user238756
Sep 10, 2018, 01:35 PM • Last activity: Sep 11, 2018, 08:20 PM
Showing page 1 of 6 total questions