* Re: Text Reformatting
2003-05-18 4:11 ` Text Reformatting Peter
@ 2003-05-18 4:23 ` CaT
2003-05-18 4:23 ` raihan
` (2 subsequent siblings)
3 siblings, 0 replies; 10+ messages in thread
From: CaT @ 2003-05-18 4:23 UTC (permalink / raw)
To: Peter; +Cc: linux-newbie
On Sun, May 18, 2003 at 12:11:19PM +0800, Peter wrote:
> I came up with the sausage
>
> cat file.txt | tr -s " " "\012" > file1.txt | fmt -u -w 105 file1.txt >
> file2.txt
>
> This does not maintain the paragraphs, however. Can sed do it and how?
sed -e 's/^[ ]\+//' -e 's/[ ]\+$//' <file.txt | fmt -u -w 105 >file1.txt
I added the 2nd regexp just to make sure there was nothing there. Tab and
a space inside the square brackets.
--
Martin's distress was in contrast to the bitter satisfaction of some
of his fellow marines as they surveyed the scene. "The Iraqis are sick
people and we are the chemotherapy," said Corporal Ryan Dupre. "I am
starting to hate this country. Wait till I get hold of a friggin' Iraqi.
No, I won't get hold of one. I'll just kill him."
- http://www.informationclearinghouse.info/article2479.htm
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: Text Reformatting
2003-05-18 4:11 ` Text Reformatting Peter
2003-05-18 4:23 ` CaT
@ 2003-05-18 4:23 ` raihan
2003-05-18 7:54 ` John Kelly
2003-05-19 15:44 ` Stephen Samuel
3 siblings, 0 replies; 10+ messages in thread
From: raihan @ 2003-05-18 4:23 UTC (permalink / raw)
To: linux-newbie
Hi,
> cat file.txt | tr -s " " "\012" > file1.txt | fmt -u -w
> 105 file1.txt > file2.txt
>
> This does not maintain the paragraphs, however. Can sed do
> it and how?
If there's a blank line between paragraphs, it should work.
Otherwise it becomes more difficult. Try opening the file
in Vim and running the command
ggVG
which reformats the whole file similar to fmt. If you don't
like the result, quit without saving anything:
:q!
Yawar
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Text Reformatting
2003-05-18 4:11 ` Text Reformatting Peter
2003-05-18 4:23 ` CaT
2003-05-18 4:23 ` raihan
@ 2003-05-18 7:54 ` John Kelly
2003-05-19 15:44 ` Stephen Samuel
3 siblings, 0 replies; 10+ messages in thread
From: John Kelly @ 2003-05-18 7:54 UTC (permalink / raw)
To: Peter, linux-newbie
Hi,
On Sunday 18 May 2003 5:11 am, Peter wrote:
> Hi,
>
> Some text I download for printing are formatted like:
>
> Because of the publicity the Iraqi government has given to the
> issue, Iraqis worry about DU.
>
> which adds more pages for printing.
>
> How can I with some command, left align the text to read
>
> Because of the publicity the Iraqi government has given to the
> issue, Iraqis worry about DU.
>
> yet maintaining the paragraphs.
>
I often cut and paste webpages into files and they are often munged as in the
example you give.
My standard way of doing this is to use vi.
Open the file in vi and do:
Press <ESC> to ensure you are in command mode.
Then type:
:%s/^\s*//
<ENTER>
If you are happy with the result, type:
ZZ
to save the modified file
else type:
:q!
to quit without saving.
regards,
John Kelly
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Text Reformatting
2003-05-18 4:11 ` Text Reformatting Peter
` (2 preceding siblings ...)
2003-05-18 7:54 ` John Kelly
@ 2003-05-19 15:44 ` Stephen Samuel
2003-05-20 2:47 ` Peter
3 siblings, 1 reply; 10+ messages in thread
From: Stephen Samuel @ 2003-05-19 15:44 UTC (permalink / raw)
To: Peter, linux-newbie
Peter wrote:
> Hi,
>
> Some text I download for printing are formatted like:
>
> Because of the publicity the Iraqi government has given to the
> issue, Iraqis worry about DU.
>
> which adds more pages for printing.
>
> How can I with some command, left align the text to read
>
> Because of the publicity the Iraqi government has given to the
> issue, Iraqis worry about DU.
>
> yet maintaining the paragraphs.
>
> When looking at the text with a word processor they are all left aligned and
> can only be changed manually line by line.
>
> I came up with the sausage
>
> cat file.txt | tr -s " " "\012" > file1.txt | fmt -u -w 105 file1.txt >
> file2.txt
>
> This does not maintain the paragraphs, however. Can sed do it and how?
>
> Thanks & regards
Mostly what you want to do is delete the leading spaces then reformat.
As long as paragraphs are separated by blank lines, the following should
work:
sed 's/^[ \t]+//' file | fmt -u -w105 > file2.txt
----------------------------------
Note that when you do the " tr [options] > somefile | fmt [options] somefile" ,
you're losing any advantage of using a pipe. The output for the
tr file is redirected into somefile, and fmt is reading explicitly
from there. The pipe is essentially unused... Either :
tr [options] | fmt [options]
or:
tr [options] > somefile ; fmt [options] somefile
The main difference: The former properly uses pipes
The later simply acknowledges that the pipe really isn't being used.
--
Stephen Samuel +1(604)876-0426 samuel@bcgreen.com
http://www.bcgreen.com/~samuel/
Powerful committed communication, reaching through fear, uncertainty and
doubt to touch the jewel within each person and bring it to life.
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: Text Reformatting
2003-05-19 15:44 ` Stephen Samuel
@ 2003-05-20 2:47 ` Peter
2003-05-20 9:59 ` Stephen Samuel
0 siblings, 1 reply; 10+ messages in thread
From: Peter @ 2003-05-20 2:47 UTC (permalink / raw)
To: Stephen Samuel, linux-newbie
Thanks Stephen,
sed 's/^[ \t]+//' file does not work, it changes nothing.
samuel@bcgreen.com said:
> Note that when you do the " tr [options] > somefile | fmt [options]
> somefile" , you're losing any advantage of using a pipe.
Well taken tip!
Regards
--
Peter
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Text Reformatting
2003-05-20 2:47 ` Peter
@ 2003-05-20 9:59 ` Stephen Samuel
0 siblings, 0 replies; 10+ messages in thread
From: Stephen Samuel @ 2003-05-20 9:59 UTC (permalink / raw)
To: Peter; +Cc: linux-newbie
Peter wrote:
> Thanks Stephen,
>
> sed 's/^[ \t]+//' file does not work, it changes nothing.
>
>
> samuel@bcgreen.com said:
>
>>Note that when you do the " tr [options] > somefile | fmt [options]
>>somefile" , you're losing any advantage of using a pipe.
>
>
> Well taken tip!
>
> Regards
Grr... I forgot the backslash before the '+' That should be:
sed 's/^[ \t]\+//' file
(you could also do
sed 's/^[ \t]*//' file
The '+' construct is (technically) a bit more efficient -- it won't
do a null replacement for an unindented line. It is, however, an
extended pattern and I sometimes worry about it's portability to
older (non-gnu) versions of sed. Ha! but never mind! Even that \t
turns out not to be portable to BSD. you need to have the literal
'tab' character. It turns out that the most portable form is:
sed 's/^[ ]*//' file
(with a space and a tabe between the sqquare brackets). You might
need to do a ctrl-v o get bash to accept the tab caracter.
--
Stephen Samuel +1(604)876-0426 samuel@bcgreen.com
http://www.bcgreen.com/~samuel/
Powerful committed communication, reaching through fear, uncertainty and
doubt to touch the jewel within each person and bring it to life.
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
^ permalink raw reply [flat|nested] 10+ messages in thread