Any tool to insert a newline each X characters in a file?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Any tool to insert a newline each X characters in a file?
Hi! I'd like to know if there's any command between the linux tools (awk, sed, cat...) that lets me insert a newline each an specified amount of characters from a text in a pipe.
Or another way to say it, something that worked like cat but outputing in a column X characters wide.
Any idea?
Thx!
At first I needed something that if called with argument 8, would print "something that if called with argument" as:
Code:
somethin
g that i
f called
with ar
gument
But then I realized that I wanted it not to cut the words, and that was much more difficult, so I don't think there's a tool able to do that. Or maybe there is, I was making a widget for SuperKaramba, and ended up implementing the behavior I wanted in python code, so I don't need it now.
However, is there is a way to do this, I'm still curious...
Great! That's just what I spent like half an hour implementing in Python :'(
I noticed that in the formatting of the manuals in Linux, a "justified" alignment is used. In fmt man doesn't seem to appear that formatting as an option. Is there any way to do that? That would definitely beat my python function... :P
I noticed that in the formatting of the manuals in Linux, a "justified" alignment is used. In fmt man doesn't seem to appear that formatting as an option. Is there any way to do that?
As it turns out, I was just looking at formatting, so here is a quick script that shows justification:
Code:
#!/bin/sh
# @(#) s1 Demonstrate text justification with roff, very crude sample.
##
# See man 7 groff for many details on the formatting directives.
NROFF=/usr/bin/nroff
cat >data1 <<EOF
Now is the
time for all good
people to come to
the aid of their country.
-- a most common quote that can be found almost anywhere.
EOF
justify() {
local FILE=$1
local J=$2
local W=$3
$NROFF <<-EOF
.ad $J
.ll $W
.so $FILE
EOF
}
echo ; echo Left
justify data1 l 25 | sed '/^$/d'
echo ; echo Right
justify data1 r 50 | sed '/^$/d'
echo ; echo Both
justify data1 b 35 | sed '/^$/d'
echo ; echo Center
justify data1 c 35 | sed '/^$/d'
exit 0
Producing:
Code:
% ./s1
Left
Now is the time for all
good people to come to
the aid of their country.
-- a most common quote
that can be found almost
anywhere.
Right
Now is the time for all good people to come to the
aid of their country. -- a most common quote that
can be found almost anywhere.
Both
Now is the time for all good people
to come to the aid of their coun-
try. -- a most common quote that
can be found almost anywhere.
Center
Now is the time for all good people
to come to the aid of their coun-
try. -- a most common quote that
can be found almost anywhere
There are lots of knobs to [gnt]roff, and other folks may have some simpler ideas.
I have heard it said that "ragged right" is best for reading ... cheers, makyo
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.