You are not logged in.

#1 2009-11-12 01:58:40

Gen2ly
Member
From: Sevierville, TN
Registered: 2009-03-06
Posts: 1,529
Website

[Solved] Bash...: Reformat command line output for long lines.

I got an output from a command that outputs a long line that I'd like to indent and chop off at the 76 character.  Currently the command outputs:

thes archla
! archla is not in the dictionary.  Possible alternatives:

arch la, arch-la, archly, Ashla, Arch, arch, ashlar, Arch's, Archean, arch's, arches, archway, Archy, Ashli, Ashly, Archer, Archie, Rachel, archer, Ariela, arched, archival, Aral, racial, Rachele, Ala, Archy's, Ashil, archaic, areal, Ashlan, Marchall, Marshal, marshal, Aila, Alla, Arly, Chlo, ache, achy, Ashla's

I suppose I might be able to find a way for sed to do this but was thinking there might be a tool that already does this.  Any ideas?

Last edited by Gen2ly (2009-11-12 04:36:27)


Setting Up a Scripting Environment | Proud donor to wikipedia - link

Offline

#2 2009-11-12 03:29:14

tavianator
Member
From: Waterloo, ON, Canada
Registered: 2007-08-21
Posts: 859
Website

Re: [Solved] Bash...: Reformat command line output for long lines.

man fmt

Offline

#3 2009-11-12 04:35:54

Gen2ly
Member
From: Sevierville, TN
Registered: 2009-03-06
Posts: 1,529
Website

Re: [Solved] Bash...: Reformat command line output for long lines.

lol, commands you never hear of.  Seems like I learn a new linux command that been there all along every day. smile  Thanks.


Setting Up a Scripting Environment | Proud donor to wikipedia - link

Offline

#4 2009-11-12 04:36:36

crouse
Arch Linux f@h Team Member
From: Iowa - USA
Registered: 2006-08-19
Posts: 907
Website

Re: [Solved] Bash...: Reformat command line output for long lines.

much easier that that


pipe it through " | cut -c 1-72"

Offline

#5 2009-11-12 04:42:33

crouse
Arch Linux f@h Team Member
From: Iowa - USA
Registered: 2006-08-19
Posts: 907
Website

Re: [Solved] Bash...: Reformat command line output for long lines.

hmmmmmm unless you want it to wrap..... in which case, cut won't work wink

Offline

#6 2009-11-16 02:58:23

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Re: [Solved] Bash...: Reformat command line output for long lines.

never heard of fmt either, but i think sed can do everything it's capable of... say, does this do what you want?

sed 's/.\{76\}/&\n\t/g'

This silver ladybug at line 28...

Offline

#7 2009-11-16 14:41:17

AlecSchueler
Member
Registered: 2009-05-30
Posts: 22

Re: [Solved] Bash...: Reformat command line output for long lines.

Edit2:
Ahh, I see now. You want to cut it off, not wrap it. Ignore this post then.

Maybe I'm misunderstood the question, but I'm surprised no one's mentioned fold.

fold -sw 76

should do it. It won't break up words or anything, and it's included in the base Arch install as far as I remember.

Edit:

Here's an example from my .bashrc showing something similar to what you seem to be doing,

function etym(){
    for term in "$@"
    do
        url="http://www.etymonline.com/index.php?term=$term"
        curl -s $url | grep "<dd " | sed 's/<[^>]*>//g' | fold -sw 79
        echo
    done
    }

Last edited by AlecSchueler (2009-11-16 14:45:05)

Offline

Board footer

Powered by FluxBB