reverse file character by character using tac
Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
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]'
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.
tac
add a comment |Â
up vote
3
down vote
favorite
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]'
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.
tac
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 haverev
?
â Kusalananda
May 28 at 6:39
Reversing characters not lines.
â Weezy
May 28 at 8:57
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
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]'
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.
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]'
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.
tac
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 haverev
?
â Kusalananda
May 28 at 6:39
Reversing characters not lines.
â Weezy
May 28 at 8:57
add a comment |Â
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 haverev
?
â 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
add a comment |Â
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.
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 then
:printf 'abncdn'|tac -r -s . |hexdump -c
->n d n c b a
, andtac -r -s . | tac -r -s .
isn't idempotent.
â Michael Homer
May 28 at 9:13
add a comment |Â
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.
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 then
:printf 'abncdn'|tac -r -s . |hexdump -c
->n d n c b a
, andtac -r -s . | tac -r -s .
isn't idempotent.
â Michael Homer
May 28 at 9:13
add a comment |Â
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.
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 then
:printf 'abncdn'|tac -r -s . |hexdump -c
->n d n c b a
, andtac -r -s . | tac -r -s .
isn't idempotent.
â Michael Homer
May 28 at 9:13
add a comment |Â
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.
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.
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 then
:printf 'abncdn'|tac -r -s . |hexdump -c
->n d n c b a
, andtac -r -s . | tac -r -s .
isn't idempotent.
â Michael Homer
May 28 at 9:13
add a comment |Â
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 then
:printf 'abncdn'|tac -r -s . |hexdump -c
->n d n c b a
, andtac -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
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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