LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-08-2007, 06:18 PM   #1
neoAKiRAz
Member
 
Registered: Jan 2006
Location: Uruguay
Distribution: Kubuntu
Posts: 48

Rep: Reputation: 15
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!

Last edited by neoAKiRAz; 05-08-2007 at 06:43 PM.
 
Old 05-08-2007, 08:22 PM   #2
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
How about a short example.
 
Old 05-08-2007, 11:18 PM   #3
neoAKiRAz
Member
 
Registered: Jan 2006
Location: Uruguay
Distribution: Kubuntu
Posts: 48

Original Poster
Rep: Reputation: 15
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...
 
Old 05-09-2007, 02:49 AM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
there most certainly is my friend,

man fmt
 
Old 05-09-2007, 06:00 PM   #5
neoAKiRAz
Member
 
Registered: Jan 2006
Location: Uruguay
Distribution: Kubuntu
Posts: 48

Original Poster
Rep: Reputation: 15
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
 
Old 05-09-2007, 07:15 PM   #6
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 735

Rep: Reputation: 76
Hi.
Quote:
Originally Posted by neoAKiRAz
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

( edit 1: addition )

Last edited by makyo; 05-09-2007 at 07:18 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Sed: insert a newline. Why does not it work? J_Szucs Linux - Software 5 06-14-2019 08:18 AM
How to insert characters by ascii code? J_Szucs Linux - General 14 06-17-2017 12:33 PM
Need to Insert Newline Char amh06 AIX 6 09-15-2006 02:35 AM
using sed to insert lines with special characters disorderly Linux - Software 26 04-20-2006 05:30 PM
how to insert special characters set2004 Linux - Newbie 2 08-05-2004 10:50 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration