What does sed $'s/[^[:print:]t]//g' do?

Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
0
down vote
favorite
The command sed $'s/[^[:print:]t]//g' is printing each line of my .txt as-is.
What is it used for? I could not find it on google.
Eg:
sed $'s/[^[:print:]t]//g' *.txt | wc -l
15909
cat *.txt | wc -l
15909
There are no edits done in the files whatsoever. What does this command do
shell-script sed grep
add a comment |Â
up vote
0
down vote
favorite
The command sed $'s/[^[:print:]t]//g' is printing each line of my .txt as-is.
What is it used for? I could not find it on google.
Eg:
sed $'s/[^[:print:]t]//g' *.txt | wc -l
15909
cat *.txt | wc -l
15909
There are no edits done in the files whatsoever. What does this command do
shell-script sed grep
1
sedis pretty heavy-handed for such a simple task.tr -dis likely faster and many implementations understand the same named character sets as used in thissedcommand.
â David Foerster
Jul 30 at 10:25
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
The command sed $'s/[^[:print:]t]//g' is printing each line of my .txt as-is.
What is it used for? I could not find it on google.
Eg:
sed $'s/[^[:print:]t]//g' *.txt | wc -l
15909
cat *.txt | wc -l
15909
There are no edits done in the files whatsoever. What does this command do
shell-script sed grep
The command sed $'s/[^[:print:]t]//g' is printing each line of my .txt as-is.
What is it used for? I could not find it on google.
Eg:
sed $'s/[^[:print:]t]//g' *.txt | wc -l
15909
cat *.txt | wc -l
15909
There are no edits done in the files whatsoever. What does this command do
shell-script sed grep
edited Jul 30 at 8:30
SivaPrasath
3,46311535
3,46311535
asked Jul 30 at 7:41
Viv
1093
1093
1
sedis pretty heavy-handed for such a simple task.tr -dis likely faster and many implementations understand the same named character sets as used in thissedcommand.
â David Foerster
Jul 30 at 10:25
add a comment |Â
1
sedis pretty heavy-handed for such a simple task.tr -dis likely faster and many implementations understand the same named character sets as used in thissedcommand.
â David Foerster
Jul 30 at 10:25
1
1
sed is pretty heavy-handed for such a simple task. tr -d is likely faster and many implementations understand the same named character sets as used in this sed command.â David Foerster
Jul 30 at 10:25
sed is pretty heavy-handed for such a simple task. tr -d is likely faster and many implementations understand the same named character sets as used in this sed command.â David Foerster
Jul 30 at 10:25
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
5
down vote
accepted
The sed command removes any character that is not printable, and not tabs, from the content of each line of input. The number of lines would not change (the newline characters are not removed as they are not part of the content of the line), but the number of characters or bytes might. Test again with wc -c for the number of bytes, wc -m for the number of characters.
The regular expression [^...] matches any single character (actually collating element) not within the [...]. In this case, it's the character class [:print:] and the tab character. The $ at the start of the string makes bash replace t with a literal tab character before calling sed.
The character class [:print:] matches characters that are printable in the current locale, i.e. alphanumeric characters, punctuation characters and space (but not tab which is a control character).
In other words, it deletes everything that is not a alphanumeric character, punctuation character, space or tab.
To write the result back to the file (an "in-place edit"), some sed implementations have a -i option for that; use sed -i or sed -i '' depending on the implementation. Be sure that the correct output is produced first though, or you may destroy your data.
1
Oh the wc -c gives me different numbers, which means it does delete some characters. How to print the characters that it is deleting.? or Line numbers for ref?
â Viv
Jul 30 at 7:53
1
Even though it removes certain chars, how come the timestamps do not change?
â Viv
Jul 30 at 7:55
2
@Viv The timestamp is not changed because no change is made to the file. The only thing that happens is that the lines are transformed an printed to the terminal.
â Kusalananda
Jul 30 at 7:57
2
@Viv Delete the^in[^...]to see what characters matches the inverse condition.
â Kusalananda
Jul 30 at 7:59
2
@Vivgrep -H $'[^[:print:]t]' *.txt, possibly.
â Kusalananda
Jul 30 at 8:03
 |Â
show 3 more comments
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
accepted
The sed command removes any character that is not printable, and not tabs, from the content of each line of input. The number of lines would not change (the newline characters are not removed as they are not part of the content of the line), but the number of characters or bytes might. Test again with wc -c for the number of bytes, wc -m for the number of characters.
The regular expression [^...] matches any single character (actually collating element) not within the [...]. In this case, it's the character class [:print:] and the tab character. The $ at the start of the string makes bash replace t with a literal tab character before calling sed.
The character class [:print:] matches characters that are printable in the current locale, i.e. alphanumeric characters, punctuation characters and space (but not tab which is a control character).
In other words, it deletes everything that is not a alphanumeric character, punctuation character, space or tab.
To write the result back to the file (an "in-place edit"), some sed implementations have a -i option for that; use sed -i or sed -i '' depending on the implementation. Be sure that the correct output is produced first though, or you may destroy your data.
1
Oh the wc -c gives me different numbers, which means it does delete some characters. How to print the characters that it is deleting.? or Line numbers for ref?
â Viv
Jul 30 at 7:53
1
Even though it removes certain chars, how come the timestamps do not change?
â Viv
Jul 30 at 7:55
2
@Viv The timestamp is not changed because no change is made to the file. The only thing that happens is that the lines are transformed an printed to the terminal.
â Kusalananda
Jul 30 at 7:57
2
@Viv Delete the^in[^...]to see what characters matches the inverse condition.
â Kusalananda
Jul 30 at 7:59
2
@Vivgrep -H $'[^[:print:]t]' *.txt, possibly.
â Kusalananda
Jul 30 at 8:03
 |Â
show 3 more comments
up vote
5
down vote
accepted
The sed command removes any character that is not printable, and not tabs, from the content of each line of input. The number of lines would not change (the newline characters are not removed as they are not part of the content of the line), but the number of characters or bytes might. Test again with wc -c for the number of bytes, wc -m for the number of characters.
The regular expression [^...] matches any single character (actually collating element) not within the [...]. In this case, it's the character class [:print:] and the tab character. The $ at the start of the string makes bash replace t with a literal tab character before calling sed.
The character class [:print:] matches characters that are printable in the current locale, i.e. alphanumeric characters, punctuation characters and space (but not tab which is a control character).
In other words, it deletes everything that is not a alphanumeric character, punctuation character, space or tab.
To write the result back to the file (an "in-place edit"), some sed implementations have a -i option for that; use sed -i or sed -i '' depending on the implementation. Be sure that the correct output is produced first though, or you may destroy your data.
1
Oh the wc -c gives me different numbers, which means it does delete some characters. How to print the characters that it is deleting.? or Line numbers for ref?
â Viv
Jul 30 at 7:53
1
Even though it removes certain chars, how come the timestamps do not change?
â Viv
Jul 30 at 7:55
2
@Viv The timestamp is not changed because no change is made to the file. The only thing that happens is that the lines are transformed an printed to the terminal.
â Kusalananda
Jul 30 at 7:57
2
@Viv Delete the^in[^...]to see what characters matches the inverse condition.
â Kusalananda
Jul 30 at 7:59
2
@Vivgrep -H $'[^[:print:]t]' *.txt, possibly.
â Kusalananda
Jul 30 at 8:03
 |Â
show 3 more comments
up vote
5
down vote
accepted
up vote
5
down vote
accepted
The sed command removes any character that is not printable, and not tabs, from the content of each line of input. The number of lines would not change (the newline characters are not removed as they are not part of the content of the line), but the number of characters or bytes might. Test again with wc -c for the number of bytes, wc -m for the number of characters.
The regular expression [^...] matches any single character (actually collating element) not within the [...]. In this case, it's the character class [:print:] and the tab character. The $ at the start of the string makes bash replace t with a literal tab character before calling sed.
The character class [:print:] matches characters that are printable in the current locale, i.e. alphanumeric characters, punctuation characters and space (but not tab which is a control character).
In other words, it deletes everything that is not a alphanumeric character, punctuation character, space or tab.
To write the result back to the file (an "in-place edit"), some sed implementations have a -i option for that; use sed -i or sed -i '' depending on the implementation. Be sure that the correct output is produced first though, or you may destroy your data.
The sed command removes any character that is not printable, and not tabs, from the content of each line of input. The number of lines would not change (the newline characters are not removed as they are not part of the content of the line), but the number of characters or bytes might. Test again with wc -c for the number of bytes, wc -m for the number of characters.
The regular expression [^...] matches any single character (actually collating element) not within the [...]. In this case, it's the character class [:print:] and the tab character. The $ at the start of the string makes bash replace t with a literal tab character before calling sed.
The character class [:print:] matches characters that are printable in the current locale, i.e. alphanumeric characters, punctuation characters and space (but not tab which is a control character).
In other words, it deletes everything that is not a alphanumeric character, punctuation character, space or tab.
To write the result back to the file (an "in-place edit"), some sed implementations have a -i option for that; use sed -i or sed -i '' depending on the implementation. Be sure that the correct output is produced first though, or you may destroy your data.
edited Jul 30 at 9:04
Stéphane Chazelas
277k52511841
277k52511841
answered Jul 30 at 7:49
Kusalananda
101k13199311
101k13199311
1
Oh the wc -c gives me different numbers, which means it does delete some characters. How to print the characters that it is deleting.? or Line numbers for ref?
â Viv
Jul 30 at 7:53
1
Even though it removes certain chars, how come the timestamps do not change?
â Viv
Jul 30 at 7:55
2
@Viv The timestamp is not changed because no change is made to the file. The only thing that happens is that the lines are transformed an printed to the terminal.
â Kusalananda
Jul 30 at 7:57
2
@Viv Delete the^in[^...]to see what characters matches the inverse condition.
â Kusalananda
Jul 30 at 7:59
2
@Vivgrep -H $'[^[:print:]t]' *.txt, possibly.
â Kusalananda
Jul 30 at 8:03
 |Â
show 3 more comments
1
Oh the wc -c gives me different numbers, which means it does delete some characters. How to print the characters that it is deleting.? or Line numbers for ref?
â Viv
Jul 30 at 7:53
1
Even though it removes certain chars, how come the timestamps do not change?
â Viv
Jul 30 at 7:55
2
@Viv The timestamp is not changed because no change is made to the file. The only thing that happens is that the lines are transformed an printed to the terminal.
â Kusalananda
Jul 30 at 7:57
2
@Viv Delete the^in[^...]to see what characters matches the inverse condition.
â Kusalananda
Jul 30 at 7:59
2
@Vivgrep -H $'[^[:print:]t]' *.txt, possibly.
â Kusalananda
Jul 30 at 8:03
1
1
Oh the wc -c gives me different numbers, which means it does delete some characters. How to print the characters that it is deleting.? or Line numbers for ref?
â Viv
Jul 30 at 7:53
Oh the wc -c gives me different numbers, which means it does delete some characters. How to print the characters that it is deleting.? or Line numbers for ref?
â Viv
Jul 30 at 7:53
1
1
Even though it removes certain chars, how come the timestamps do not change?
â Viv
Jul 30 at 7:55
Even though it removes certain chars, how come the timestamps do not change?
â Viv
Jul 30 at 7:55
2
2
@Viv The timestamp is not changed because no change is made to the file. The only thing that happens is that the lines are transformed an printed to the terminal.
â Kusalananda
Jul 30 at 7:57
@Viv The timestamp is not changed because no change is made to the file. The only thing that happens is that the lines are transformed an printed to the terminal.
â Kusalananda
Jul 30 at 7:57
2
2
@Viv Delete the
^ in [^...] to see what characters matches the inverse condition.â Kusalananda
Jul 30 at 7:59
@Viv Delete the
^ in [^...] to see what characters matches the inverse condition.â Kusalananda
Jul 30 at 7:59
2
2
@Viv
grep -H $'[^[:print:]t]' *.txt, possibly.â Kusalananda
Jul 30 at 8:03
@Viv
grep -H $'[^[:print:]t]' *.txt, possibly.â Kusalananda
Jul 30 at 8:03
 |Â
show 3 more comments
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%2f459273%2fwhat-does-sed-s-print-t-g-do%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
1
sedis pretty heavy-handed for such a simple task.tr -dis likely faster and many implementations understand the same named character sets as used in thissedcommand.â David Foerster
Jul 30 at 10:25