wrapping text not exceeding 80 characters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting wrapping text not exceeding 80 characters
# 1  
Old 09-22-2011
wrapping text not exceeding 80 characters

I have a file where the text might exceed 80 characters. I want to have the maximum text lengths to be 80, and cut text from a space.

I written an awk script below but does not seem to work very well

Code:
{
    gsub("\t"," ")
    $0 = line $0
    while (length <= WIDTH) {
        line = $0
        more = getline
        gsub("\t"," ")
        if (more)
            $0 = line " " $0
        else
            $0 = line
            break
    }
    while (length >= WIDTH) {
        print substr($0,1,WIDTH)
        $0 = substr($0,WIDTH+1)
    }
    line = $0 " "
}

END { print }

# 2  
Old 09-22-2011
Have you tried this:
Code:
cut -c1-80 File

# 3  
Old 09-22-2011
or man fold
# 4  
Old 09-22-2011
Brilliant
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

UNIX mail and wrapping

Greetings, I am by no means a Unix expert and hope that someone here can help me out. I am sending an email from within a Progress character program. This works fine. My issue is that I would like to send more than 80 characters and the email is wrapping at 80 chars. Is this an email... (9 Replies)
Discussion started by: Nosredna
9 Replies

2. Shell Programming and Scripting

SELECT and wrapping to next column

Hi all, Am trying to write a menu driven script using SELECT and if I have more than 4 options, it wraps to the next column. That is if I have 6 choices, items 5 and 6 are in the second column. Is there any settings that control this behavior or is it due to some stty settings? stty -a... (3 Replies)
Discussion started by: newbie_01
3 Replies

3. Shell Programming and Scripting

Line Wrapping using Sed

Hi, I want to wrap the lines if a line starts with number. I tried the following sed command, but I do not get the required output. It is replacing the first number. Can some one please help me on this? Command I used sed -e :a -e '$!N;s/\n//;ta' -e 'P;D' testfile I/P file:... (2 Replies)
Discussion started by: christineidanny
2 Replies

4. Shell Programming and Scripting

Improper wrapping of text in split of file

Hi I am using shell script where I am calling SQLPLUS and executing one PL/SQL block. This PL/SQL block generates the spool file for example splfile.txt. After successful generation of spool file I use nawk to split this file into 2 different files. Till here no issues. nawk... (1 Reply)
Discussion started by: shekharjchandra
1 Replies

5. UNIX for Dummies Questions & Answers

Putty and wrapping on SunOS 5.9

I am very frustrated with this. I've added the following into my .profile and .bashrc: #this one makes sure that long commands strings line wrap to the next line && return #instead of wrapping onto the start of the same line. shopt -s checkwinsize However, it just never works for me.... (7 Replies)
Discussion started by: mrwatkin
7 Replies

6. AIX

email alerts for memory or cpu exceeding thresholds

Hi Guys, I hope this is an easy question: I need some kind of script or an idea how I can convince syslog to send an email to root or someone else once cpu usage exceeds 95% or the memory consumption (maybe via AVM value times 4k) exceeds 85% of my real memory on any of my 700 lpars. We're... (4 Replies)
Discussion started by: zxmaus
4 Replies

7. Shell Programming and Scripting

automatic word wrapping

Hallo, I want to have this Output: Name Street Phone Mail Favorite_thing_o f_what_ever_you_ want Jak street1 0123 jak@test blue egs .com O'Neill street2 4567 ... (1 Reply)
Discussion started by: wiseguy
1 Replies

8. Shell Programming and Scripting

Help required in displaying lines exceeding 79 chars along with their line numbers ??

Hi folks, I am looking for a solution to display those lines in any file that contains 80 or more characters along with their corresponding line number in the file. The below script will print the lines with their corresponding line numbers... sed = Sample.cpp | sed 'N;s/\n/\t/;... (8 Replies)
Discussion started by: frozensmilz
8 Replies

9. Shell Programming and Scripting

Comparing files exceeding 1.7GB

HI, I have few files in two folders with the same name exceeding 2GB.I need to compare these files. These files are in the format File1 in first folder 1|20080430|IA001|TREND DYNAMICS INC 2|20080430|IP001|AMERITAS LIFE INSURANCE CO 3|20080430|IP002|TRANSAMERICA LIFE INSURANCE CO File1... (3 Replies)
Discussion started by: ragavhere
3 Replies

10. UNIX for Dummies Questions & Answers

File size exceeding 2GB

I am working on HP-Unix. I have a 600 MB file in compressed form. During decompression, when file size reaches 2GB, decompression aborts. What should be done? (3 Replies)
Discussion started by: Nadeem Mistry
3 Replies
Login or Register to Ask a Question