search and replace 1 or more spaces after a period of a files to 2 spaces

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











up vote
2
down vote

favorite












Q: What command would you give to print (display on the screen) the corrected text of userNotes.txt with all sentence endings having required two blanks before the start of the next sentence?



here is my code



sed 's/.s/.ss/' 


but this also changed the line where it ended with dot and 2 spaces to dot and 3 spaces.










share|improve this question







New contributor




Khang Nguyen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • Hello @Khang Nguyen. Would you please provide an example?
    – Goro
    1 hour ago










  • For example, this is OK: Turn the knob. Push the “on” button. This is not: Turn the knob. Push the “on” button.
    – Khang Nguyen
    1 hour ago










  • Do you mean you want to unify the spaces after the dots? I mean make same space after dots?
    – Goro
    56 mins ago







  • 1




    Yes! i think that's what i have to do
    – Khang Nguyen
    54 mins ago










  • Pelase see my answer and let me know
    – Goro
    53 mins ago















up vote
2
down vote

favorite












Q: What command would you give to print (display on the screen) the corrected text of userNotes.txt with all sentence endings having required two blanks before the start of the next sentence?



here is my code



sed 's/.s/.ss/' 


but this also changed the line where it ended with dot and 2 spaces to dot and 3 spaces.










share|improve this question







New contributor




Khang Nguyen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • Hello @Khang Nguyen. Would you please provide an example?
    – Goro
    1 hour ago










  • For example, this is OK: Turn the knob. Push the “on” button. This is not: Turn the knob. Push the “on” button.
    – Khang Nguyen
    1 hour ago










  • Do you mean you want to unify the spaces after the dots? I mean make same space after dots?
    – Goro
    56 mins ago







  • 1




    Yes! i think that's what i have to do
    – Khang Nguyen
    54 mins ago










  • Pelase see my answer and let me know
    – Goro
    53 mins ago













up vote
2
down vote

favorite









up vote
2
down vote

favorite











Q: What command would you give to print (display on the screen) the corrected text of userNotes.txt with all sentence endings having required two blanks before the start of the next sentence?



here is my code



sed 's/.s/.ss/' 


but this also changed the line where it ended with dot and 2 spaces to dot and 3 spaces.










share|improve this question







New contributor




Khang Nguyen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











Q: What command would you give to print (display on the screen) the corrected text of userNotes.txt with all sentence endings having required two blanks before the start of the next sentence?



here is my code



sed 's/.s/.ss/' 


but this also changed the line where it ended with dot and 2 spaces to dot and 3 spaces.







text-processing sed






share|improve this question







New contributor




Khang Nguyen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




Khang Nguyen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




Khang Nguyen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 1 hour ago









Khang Nguyen

132




132




New contributor




Khang Nguyen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Khang Nguyen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Khang Nguyen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











  • Hello @Khang Nguyen. Would you please provide an example?
    – Goro
    1 hour ago










  • For example, this is OK: Turn the knob. Push the “on” button. This is not: Turn the knob. Push the “on” button.
    – Khang Nguyen
    1 hour ago










  • Do you mean you want to unify the spaces after the dots? I mean make same space after dots?
    – Goro
    56 mins ago







  • 1




    Yes! i think that's what i have to do
    – Khang Nguyen
    54 mins ago










  • Pelase see my answer and let me know
    – Goro
    53 mins ago

















  • Hello @Khang Nguyen. Would you please provide an example?
    – Goro
    1 hour ago










  • For example, this is OK: Turn the knob. Push the “on” button. This is not: Turn the knob. Push the “on” button.
    – Khang Nguyen
    1 hour ago










  • Do you mean you want to unify the spaces after the dots? I mean make same space after dots?
    – Goro
    56 mins ago







  • 1




    Yes! i think that's what i have to do
    – Khang Nguyen
    54 mins ago










  • Pelase see my answer and let me know
    – Goro
    53 mins ago
















Hello @Khang Nguyen. Would you please provide an example?
– Goro
1 hour ago




Hello @Khang Nguyen. Would you please provide an example?
– Goro
1 hour ago












For example, this is OK: Turn the knob. Push the “on” button. This is not: Turn the knob. Push the “on” button.
– Khang Nguyen
1 hour ago




For example, this is OK: Turn the knob. Push the “on” button. This is not: Turn the knob. Push the “on” button.
– Khang Nguyen
1 hour ago












Do you mean you want to unify the spaces after the dots? I mean make same space after dots?
– Goro
56 mins ago





Do you mean you want to unify the spaces after the dots? I mean make same space after dots?
– Goro
56 mins ago





1




1




Yes! i think that's what i have to do
– Khang Nguyen
54 mins ago




Yes! i think that's what i have to do
– Khang Nguyen
54 mins ago












Pelase see my answer and let me know
– Goro
53 mins ago





Pelase see my answer and let me know
– Goro
53 mins ago











2 Answers
2






active

oldest

votes

















up vote
3
down vote



accepted










sed 's/.[[:space:]]1,/. /g'


Would replace a dot (matched by . or [.], remember . matches any character) followed by one or more whitespace characters ([[:space:]] being the standard equivalent of s) with . followed by two spaces.



You may want to do that for ! and ? as well:



sed 's/([.!?])[[:space:]]1,/1 /g'


With recent versions of GNU sed, you can shorten it to:



sed -E 's/([.!?])s+/1 /g'


Or with perl:



perl -lne 's/[.!?]Ks+/ /g'


[[:space:]] and s matches any whitespace character (though with perl that's limited to the ASCII ones). That includes CR characters though which occur at the end of the lines in MS-DOS text files but are otherwise generally not used as spacing. So those commands may end up breaking MS-DOS line delimiters if applied on MS-DOS formatted files.



Instead of [[:space:]]/s, you could use [[:blank:]]/h which do not include CR (h is supported by perl, but not GNU sed).






share|improve this answer






















  • the 1st command worked. thank you so much
    – Khang Nguyen
    46 mins ago

















up vote
2
down vote













Let's say your text is saved in a file called 'file', then you an use awk as follows



cat file
this is OK: Turn the knob. Push the u201conu201d button. This is not: Turn the knob. Push the u201conu201d button.

awk '$1=$1' OFS=" " file


or sed as follows:



sed -E "s/[[:space:]]+/ /g" file





share|improve this answer






















  • sorry but i have to use sed for this assignment
    – Khang Nguyen
    50 mins ago










  • Ah ok I will update the answer ;-)
    – Goro
    50 mins ago










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
);



);






Khang Nguyen is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f472084%2fsearch-and-replace-1-or-more-spaces-after-a-period-of-a-files-to-2-spaces%23new-answer', 'question_page');

);

Post as a guest






























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
3
down vote



accepted










sed 's/.[[:space:]]1,/. /g'


Would replace a dot (matched by . or [.], remember . matches any character) followed by one or more whitespace characters ([[:space:]] being the standard equivalent of s) with . followed by two spaces.



You may want to do that for ! and ? as well:



sed 's/([.!?])[[:space:]]1,/1 /g'


With recent versions of GNU sed, you can shorten it to:



sed -E 's/([.!?])s+/1 /g'


Or with perl:



perl -lne 's/[.!?]Ks+/ /g'


[[:space:]] and s matches any whitespace character (though with perl that's limited to the ASCII ones). That includes CR characters though which occur at the end of the lines in MS-DOS text files but are otherwise generally not used as spacing. So those commands may end up breaking MS-DOS line delimiters if applied on MS-DOS formatted files.



Instead of [[:space:]]/s, you could use [[:blank:]]/h which do not include CR (h is supported by perl, but not GNU sed).






share|improve this answer






















  • the 1st command worked. thank you so much
    – Khang Nguyen
    46 mins ago














up vote
3
down vote



accepted










sed 's/.[[:space:]]1,/. /g'


Would replace a dot (matched by . or [.], remember . matches any character) followed by one or more whitespace characters ([[:space:]] being the standard equivalent of s) with . followed by two spaces.



You may want to do that for ! and ? as well:



sed 's/([.!?])[[:space:]]1,/1 /g'


With recent versions of GNU sed, you can shorten it to:



sed -E 's/([.!?])s+/1 /g'


Or with perl:



perl -lne 's/[.!?]Ks+/ /g'


[[:space:]] and s matches any whitespace character (though with perl that's limited to the ASCII ones). That includes CR characters though which occur at the end of the lines in MS-DOS text files but are otherwise generally not used as spacing. So those commands may end up breaking MS-DOS line delimiters if applied on MS-DOS formatted files.



Instead of [[:space:]]/s, you could use [[:blank:]]/h which do not include CR (h is supported by perl, but not GNU sed).






share|improve this answer






















  • the 1st command worked. thank you so much
    – Khang Nguyen
    46 mins ago












up vote
3
down vote



accepted







up vote
3
down vote



accepted






sed 's/.[[:space:]]1,/. /g'


Would replace a dot (matched by . or [.], remember . matches any character) followed by one or more whitespace characters ([[:space:]] being the standard equivalent of s) with . followed by two spaces.



You may want to do that for ! and ? as well:



sed 's/([.!?])[[:space:]]1,/1 /g'


With recent versions of GNU sed, you can shorten it to:



sed -E 's/([.!?])s+/1 /g'


Or with perl:



perl -lne 's/[.!?]Ks+/ /g'


[[:space:]] and s matches any whitespace character (though with perl that's limited to the ASCII ones). That includes CR characters though which occur at the end of the lines in MS-DOS text files but are otherwise generally not used as spacing. So those commands may end up breaking MS-DOS line delimiters if applied on MS-DOS formatted files.



Instead of [[:space:]]/s, you could use [[:blank:]]/h which do not include CR (h is supported by perl, but not GNU sed).






share|improve this answer














sed 's/.[[:space:]]1,/. /g'


Would replace a dot (matched by . or [.], remember . matches any character) followed by one or more whitespace characters ([[:space:]] being the standard equivalent of s) with . followed by two spaces.



You may want to do that for ! and ? as well:



sed 's/([.!?])[[:space:]]1,/1 /g'


With recent versions of GNU sed, you can shorten it to:



sed -E 's/([.!?])s+/1 /g'


Or with perl:



perl -lne 's/[.!?]Ks+/ /g'


[[:space:]] and s matches any whitespace character (though with perl that's limited to the ASCII ones). That includes CR characters though which occur at the end of the lines in MS-DOS text files but are otherwise generally not used as spacing. So those commands may end up breaking MS-DOS line delimiters if applied on MS-DOS formatted files.



Instead of [[:space:]]/s, you could use [[:blank:]]/h which do not include CR (h is supported by perl, but not GNU sed).







share|improve this answer














share|improve this answer



share|improve this answer








edited 37 mins ago

























answered 48 mins ago









Stéphane Chazelas

286k53528866




286k53528866











  • the 1st command worked. thank you so much
    – Khang Nguyen
    46 mins ago
















  • the 1st command worked. thank you so much
    – Khang Nguyen
    46 mins ago















the 1st command worked. thank you so much
– Khang Nguyen
46 mins ago




the 1st command worked. thank you so much
– Khang Nguyen
46 mins ago












up vote
2
down vote













Let's say your text is saved in a file called 'file', then you an use awk as follows



cat file
this is OK: Turn the knob. Push the u201conu201d button. This is not: Turn the knob. Push the u201conu201d button.

awk '$1=$1' OFS=" " file


or sed as follows:



sed -E "s/[[:space:]]+/ /g" file





share|improve this answer






















  • sorry but i have to use sed for this assignment
    – Khang Nguyen
    50 mins ago










  • Ah ok I will update the answer ;-)
    – Goro
    50 mins ago














up vote
2
down vote













Let's say your text is saved in a file called 'file', then you an use awk as follows



cat file
this is OK: Turn the knob. Push the u201conu201d button. This is not: Turn the knob. Push the u201conu201d button.

awk '$1=$1' OFS=" " file


or sed as follows:



sed -E "s/[[:space:]]+/ /g" file





share|improve this answer






















  • sorry but i have to use sed for this assignment
    – Khang Nguyen
    50 mins ago










  • Ah ok I will update the answer ;-)
    – Goro
    50 mins ago












up vote
2
down vote










up vote
2
down vote









Let's say your text is saved in a file called 'file', then you an use awk as follows



cat file
this is OK: Turn the knob. Push the u201conu201d button. This is not: Turn the knob. Push the u201conu201d button.

awk '$1=$1' OFS=" " file


or sed as follows:



sed -E "s/[[:space:]]+/ /g" file





share|improve this answer














Let's say your text is saved in a file called 'file', then you an use awk as follows



cat file
this is OK: Turn the knob. Push the u201conu201d button. This is not: Turn the knob. Push the u201conu201d button.

awk '$1=$1' OFS=" " file


or sed as follows:



sed -E "s/[[:space:]]+/ /g" file






share|improve this answer














share|improve this answer



share|improve this answer








edited 45 mins ago

























answered 51 mins ago









Goro

5,05452459




5,05452459











  • sorry but i have to use sed for this assignment
    – Khang Nguyen
    50 mins ago










  • Ah ok I will update the answer ;-)
    – Goro
    50 mins ago
















  • sorry but i have to use sed for this assignment
    – Khang Nguyen
    50 mins ago










  • Ah ok I will update the answer ;-)
    – Goro
    50 mins ago















sorry but i have to use sed for this assignment
– Khang Nguyen
50 mins ago




sorry but i have to use sed for this assignment
– Khang Nguyen
50 mins ago












Ah ok I will update the answer ;-)
– Goro
50 mins ago




Ah ok I will update the answer ;-)
– Goro
50 mins ago










Khang Nguyen is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















Khang Nguyen is a new contributor. Be nice, and check out our Code of Conduct.












Khang Nguyen is a new contributor. Be nice, and check out our Code of Conduct.











Khang Nguyen is a new contributor. Be nice, and check out our Code of Conduct.













 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f472084%2fsearch-and-replace-1-or-more-spaces-after-a-period-of-a-files-to-2-spaces%23new-answer', 'question_page');

);

Post as a guest













































































Comments

Popular posts from this blog

What does second last employer means? [closed]

Installing NextGIS Connect into QGIS 3?

One-line joke