sed: format long lines

RT @tomjones76: sed might be one consideration.

sed -l 100 -n ”l input_file

eg:

assume a file called text_file with one line and lots of text

this is a very very very very long linethis is a very very very very long linethis is a very very very very long linethis is a very very very very long linethis is a very very very very long linethis is a very very very very long linethis is a very very very very long linethis is a very very very very long linethis is a very very very very long linethis is a very very very very long linethis is a very very very very long linethis is a very very very very long linethis is a very very very very long linethis is a very very very very long linethis is a very very very very long linethis is a very very very very long linethis is a very very very very long linethis is a very very very very long linethis is a very very very very long linethis is a very very very very long linethis is a very very very very long linethis is a very very very very long linethis is a very very very very long linethis is a very very very very long linethis is a very very very very long linethis is a very very very very long linethis is a very very very very long linethis is a very very very very long linethis is a very very very very long line

after running (using 15 instead of 100 for illustration):

sed -l 15 -n ”l text_file

you’d get:

this is a very\
very very ver\
y long linethi\
s is a very ve\
ry very very l\
ong linethis i\
s a very very \
very very long\
linethis is a\
very very ver\
y very long li\
nethis is a ve\
ry very very v\
ery long linet\
his is a very \
very very very\
long linethis\
is a very ver\
y very very lo\
ng linethis is\
a very very v\
ery very long \
linethis is a \
very very very\
very long lin\
ethis is a ver\
y very very ve\
ry long lineth\
is is a very v\
ery very very \
long linethis \
is a very very\
very very lon\
g linethis is \
a very very ve\
ry very long l\
inethis is a v\
ery very very \
very long line\
this is a very\
very very ver\
y long linethi\
s is a very ve\
ry very very l\
ong linethis i\
s a very very \
very very long\
linethis is a\
very very ver\
y very long li\
nethis is a ve\
ry very very v\
ery long linet\
his is a very \
very very very\
long linethis\
is a very ver\
y very very lo\
ng linethis is\
a very very v\
ery very long \
linethis is a \
very very very\
very long lin\
ethis is a ver\
y very very ve\
ry long lineth\
is is a very v\
ery very very \
long linethis \
is a very very\
very very lon\
g linethis is \
a very very ve\
ry very long l\
inethis is a v\
ery very very \
very long line\
this is a very\
very very ver\
y long line$
jdoe@jdoe-desktop:~/format_text$

critique:

don’t know whats up with those slashes etc. and the $ at the end. When/if I understand I will let you know.

this should atleast solve your problem of buffering at command line and displaying output on command line as well for quick investigation.

i would also suggest M,N syntax of sed’s print command that enables you to specify which set of lines you’d like to investigate.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s