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

The name of the pictureThe name of the pictureThe name of the pictureClash 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







share|improve this question

















  • 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

















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







share|improve this question

















  • 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













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







share|improve this question













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









share|improve this question












share|improve this question




share|improve this question








edited Jul 30 at 8:30









SivaPrasath

3,46311535




3,46311535









asked Jul 30 at 7:41









Viv

1093




1093







  • 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













  • 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








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











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.






share|improve this answer



















  • 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




    @Viv grep -H $'[^[:print:]t]' *.txt, possibly.
    – Kusalananda
    Jul 30 at 8:03











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%2f459273%2fwhat-does-sed-s-print-t-g-do%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










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.






share|improve this answer



















  • 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




    @Viv grep -H $'[^[:print:]t]' *.txt, possibly.
    – Kusalananda
    Jul 30 at 8:03















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.






share|improve this answer



















  • 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




    @Viv grep -H $'[^[:print:]t]' *.txt, possibly.
    – Kusalananda
    Jul 30 at 8:03













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.






share|improve this answer















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.







share|improve this answer















share|improve this answer



share|improve this answer








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




    @Viv grep -H $'[^[:print:]t]' *.txt, possibly.
    – Kusalananda
    Jul 30 at 8:03













  • 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




    @Viv grep -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













 

draft saved


draft discarded


























 


draft saved


draft discarded














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













































































Popular posts from this blog

Peggy Mitchell

Palaiologos

The Forum (Inglewood, California)