reverse file character by character using tac

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
3
down vote

favorite
1












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.







share|improve this question





















  • So did you try the command it told you to or not?
    – Michael Homer
    May 28 at 6:35










  • Are you talking about reversing the order of the lines and then reversing the order of the characters of the lines as well? Do you have rev?
    – Kusalananda
    May 28 at 6:39










  • Reversing characters not lines.
    – Weezy
    May 28 at 8:57














up vote
3
down vote

favorite
1












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.







share|improve this question





















  • So did you try the command it told you to or not?
    – Michael Homer
    May 28 at 6:35










  • Are you talking about reversing the order of the lines and then reversing the order of the characters of the lines as well? Do you have rev?
    – Kusalananda
    May 28 at 6:39










  • Reversing characters not lines.
    – Weezy
    May 28 at 8:57












up vote
3
down vote

favorite
1









up vote
3
down vote

favorite
1






1





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.







share|improve this question













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.









share|improve this question












share|improve this question




share|improve this question








edited May 28 at 10:49









Jeff Schaller

31k846105




31k846105









asked May 28 at 6:29









Weezy

1184




1184











  • So did you try the command it told you to or not?
    – Michael Homer
    May 28 at 6:35










  • Are you talking about reversing the order of the lines and then reversing the order of the characters of the lines as well? Do you have rev?
    – Kusalananda
    May 28 at 6:39










  • Reversing characters not lines.
    – Weezy
    May 28 at 8:57
















  • So did you try the command it told you to or not?
    – Michael Homer
    May 28 at 6:35










  • Are you talking about reversing the order of the lines and then reversing the order of the characters of the lines as well? Do you have rev?
    – Kusalananda
    May 28 at 6:39










  • Reversing characters not lines.
    – Weezy
    May 28 at 8:57















So did you try the command it told you to or not?
– Michael Homer
May 28 at 6:35




So did you try the command it told you to or not?
– Michael Homer
May 28 at 6:35












Are you talking about reversing the order of the lines and then reversing the order of the characters of the lines as well? Do you have rev?
– Kusalananda
May 28 at 6:39




Are you talking about reversing the order of the lines and then reversing the order of the characters of the lines as well? Do you have rev?
– Kusalananda
May 28 at 6:39












Reversing characters not lines.
– Weezy
May 28 at 8:57




Reversing characters not lines.
– Weezy
May 28 at 8:57










1 Answer
1






active

oldest

votes

















up vote
5
down vote



accepted










To reverse a file character-by-character using tac, use:



tac -r -s 'x|[^x]'


This is documented in info tac:




# Reverse a file character by character.
tac -r -s 'x|[^x]'



-r causes the separator to be treated as a regular expression. -s SEP uses SEP as the separator. x|[^x] is a regular expression that matches every character (those that are x, and those that are not x).



$ cat testfile
abc
def
ghi
$ tac -r -s 'x|[^x]' testfile

ihg
fed
cba%
$


tac file is not the same as cat file unless file has only one line. tac -r file is the same as tac file because the default separator is n, which is the same when treated as a regular expression and not.






share|improve this answer





















  • Wouldn't . work just as well as the regex? What does this match that . doesn't? n?
    – muru
    May 28 at 9:06






  • 1




    @muru Yes, if you use . it swaps bytes over the n: printf 'abncdn'|tac -r -s . |hexdump -c -> n d n c b a, and tac -r -s . | tac -r -s . isn't idempotent.
    – Michael Homer
    May 28 at 9:13










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f446410%2freverse-file-character-by-character-using-tac%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
5
down vote



accepted










To reverse a file character-by-character using tac, use:



tac -r -s 'x|[^x]'


This is documented in info tac:




# Reverse a file character by character.
tac -r -s 'x|[^x]'



-r causes the separator to be treated as a regular expression. -s SEP uses SEP as the separator. x|[^x] is a regular expression that matches every character (those that are x, and those that are not x).



$ cat testfile
abc
def
ghi
$ tac -r -s 'x|[^x]' testfile

ihg
fed
cba%
$


tac file is not the same as cat file unless file has only one line. tac -r file is the same as tac file because the default separator is n, which is the same when treated as a regular expression and not.






share|improve this answer





















  • Wouldn't . work just as well as the regex? What does this match that . doesn't? n?
    – muru
    May 28 at 9:06






  • 1




    @muru Yes, if you use . it swaps bytes over the n: printf 'abncdn'|tac -r -s . |hexdump -c -> n d n c b a, and tac -r -s . | tac -r -s . isn't idempotent.
    – Michael Homer
    May 28 at 9:13














up vote
5
down vote



accepted










To reverse a file character-by-character using tac, use:



tac -r -s 'x|[^x]'


This is documented in info tac:




# Reverse a file character by character.
tac -r -s 'x|[^x]'



-r causes the separator to be treated as a regular expression. -s SEP uses SEP as the separator. x|[^x] is a regular expression that matches every character (those that are x, and those that are not x).



$ cat testfile
abc
def
ghi
$ tac -r -s 'x|[^x]' testfile

ihg
fed
cba%
$


tac file is not the same as cat file unless file has only one line. tac -r file is the same as tac file because the default separator is n, which is the same when treated as a regular expression and not.






share|improve this answer





















  • Wouldn't . work just as well as the regex? What does this match that . doesn't? n?
    – muru
    May 28 at 9:06






  • 1




    @muru Yes, if you use . it swaps bytes over the n: printf 'abncdn'|tac -r -s . |hexdump -c -> n d n c b a, and tac -r -s . | tac -r -s . isn't idempotent.
    – Michael Homer
    May 28 at 9:13












up vote
5
down vote



accepted







up vote
5
down vote



accepted






To reverse a file character-by-character using tac, use:



tac -r -s 'x|[^x]'


This is documented in info tac:




# Reverse a file character by character.
tac -r -s 'x|[^x]'



-r causes the separator to be treated as a regular expression. -s SEP uses SEP as the separator. x|[^x] is a regular expression that matches every character (those that are x, and those that are not x).



$ cat testfile
abc
def
ghi
$ tac -r -s 'x|[^x]' testfile

ihg
fed
cba%
$


tac file is not the same as cat file unless file has only one line. tac -r file is the same as tac file because the default separator is n, which is the same when treated as a regular expression and not.






share|improve this answer













To reverse a file character-by-character using tac, use:



tac -r -s 'x|[^x]'


This is documented in info tac:




# Reverse a file character by character.
tac -r -s 'x|[^x]'



-r causes the separator to be treated as a regular expression. -s SEP uses SEP as the separator. x|[^x] is a regular expression that matches every character (those that are x, and those that are not x).



$ cat testfile
abc
def
ghi
$ tac -r -s 'x|[^x]' testfile

ihg
fed
cba%
$


tac file is not the same as cat file unless file has only one line. tac -r file is the same as tac file because the default separator is n, which is the same when treated as a regular expression and not.







share|improve this answer













share|improve this answer



share|improve this answer











answered May 28 at 6:48









Michael Homer

42.3k6108148




42.3k6108148











  • Wouldn't . work just as well as the regex? What does this match that . doesn't? n?
    – muru
    May 28 at 9:06






  • 1




    @muru Yes, if you use . it swaps bytes over the n: printf 'abncdn'|tac -r -s . |hexdump -c -> n d n c b a, and tac -r -s . | tac -r -s . isn't idempotent.
    – Michael Homer
    May 28 at 9:13
















  • Wouldn't . work just as well as the regex? What does this match that . doesn't? n?
    – muru
    May 28 at 9:06






  • 1




    @muru Yes, if you use . it swaps bytes over the n: printf 'abncdn'|tac -r -s . |hexdump -c -> n d n c b a, and tac -r -s . | tac -r -s . isn't idempotent.
    – Michael Homer
    May 28 at 9:13















Wouldn't . work just as well as the regex? What does this match that . doesn't? n?
– muru
May 28 at 9:06




Wouldn't . work just as well as the regex? What does this match that . doesn't? n?
– muru
May 28 at 9:06




1




1




@muru Yes, if you use . it swaps bytes over the n: printf 'abncdn'|tac -r -s . |hexdump -c -> n d n c b a, and tac -r -s . | tac -r -s . isn't idempotent.
– Michael Homer
May 28 at 9:13




@muru Yes, if you use . it swaps bytes over the n: printf 'abncdn'|tac -r -s . |hexdump -c -> n d n c b a, and tac -r -s . | tac -r -s . isn't idempotent.
– Michael Homer
May 28 at 9:13












 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f446410%2freverse-file-character-by-character-using-tac%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?