search and replace 1 or more spaces after a period of a files to 2 spaces
Clash 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.
text-processing sed
New contributor
 |Â
show 1 more comment
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.
text-processing sed
New contributor
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
 |Â
show 1 more comment
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.
text-processing sed
New contributor
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
text-processing sed
New contributor
New contributor
New contributor
asked 1 hour ago
Khang Nguyen
132
132
New contributor
New contributor
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
 |Â
show 1 more comment
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
 |Â
show 1 more comment
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
).
the 1st command worked. thank you so much
â Khang Nguyen
46 mins ago
add a comment |Â
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
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
add a comment |Â
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
).
the 1st command worked. thank you so much
â Khang Nguyen
46 mins ago
add a comment |Â
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
).
the 1st command worked. thank you so much
â Khang Nguyen
46 mins ago
add a comment |Â
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
).
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
).
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
add a comment |Â
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
add a comment |Â
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
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
add a comment |Â
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
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
add a comment |Â
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
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
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
add a comment |Â
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
add a comment |Â
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.
Khang Nguyen is a new contributor. Be nice, and check out our Code of Conduct.
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%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
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
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