Putting new line after certain number of character


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Putting new line after certain number of character
# 1  
Old 03-22-2009
Putting new line after certain number of character

Hi,
I want, if a line is more than 80 characters length then put a new line with 4 space after each 80 characters to indent the data at same position.

Input:
200 Geoid and gravity anomaly data of conjugate regions of Bay of Bengal and Enderby Basin: New constraints on breakup and early spreading history between India and Antarctica
330 Institute of Documentation training and teseting, Dona, Sasan
480 Frente maritimo. Montevideo
490 ^v7^p75-86
620 Aquatic communities%Benthos%Fishing grounds%Geomorphology%Topographic surveying%Hydrodynamic equations%Mathematical models%Tidal constants%Tidal constituents%Wind-driven currents
621 Sparus pagrus
485 1990
623 Red porgy
010 Marine


Output:

200 Geoid and gravity anomaly data of conjugate regions of Bay of Bengal and En
derby Basin: New constraints on breakup and early spreading history between
India and Antarctica
330 Institute of Documentation training and teseting, Dona, Sasan
480 Frente maritimo. Montevideo
490 ^v7^p75-86
620 Aquatic communities%Benthos%Fishing grounds%Geomorphology%Topographic surve
ying%Hydrodynamic equations%Mathematical models%Tidal constants%Tidal const
ituents%Wind-driven currents
621 Sparus pagrus
485 1990
623 Red porgy
010 Marine
# 2  
Old 03-22-2009

Code:
awk 'BEGIN { len = 80 }
   length <= 80 { print; next }
   {
     print substr($0,1,len)
     $0 = substr( $0, len + 1)
     while ( length >= len - 4 ) {
        printf "    %s\n", substr($0,1,len - 4)
        $0 = substr( $0, len - 3)
      }
     if ( length ) printf "    %s\n", $0
   }
' "$FILE"

# 3  
Old 03-22-2009
Thank you very much !!!
# 4  
Old 03-22-2009
I know it doesn't add 4 spaces before the newline but if you basically want to get max 80 chars per line and wrap the rest, this will do that:

Code:
fold <input_file>

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Identifying a sentence and putting it on a new line

I am revisiting the problem of sentence splitting. I have a Perl Script which splits a para into sentences, but acronyms and short forms create an issue #!/usr/bin/perl use feature qw/say/; use strict; use warnings; my $s; my @arr; while(<>) { chomp $_; $s .= $_ . " "; } @arr... (2 Replies)
Discussion started by: gimley
2 Replies

2. Shell Programming and Scripting

How to accept command line argument as character or text if number is entered?

Hello Does the unix korn shell provide a function to convert number entered in command line argument to text or Character so that in next step i will convert Chr to Hex (6 Replies)
Discussion started by: aadityapatel198
6 Replies

3. Shell Programming and Scripting

How to print a particular character n number of times in a line??

hi, Is it possible to print a particular character n number of times in a line? for example. i am print the following line using echo command.. echo "files successfully moved" i want to count the number of characters that are been displayed. i am doin it using echo "files... (8 Replies)
Discussion started by: Little
8 Replies

4. Shell Programming and Scripting

Help awk/sed: putting a space after numbers:to separate number and characters.

Hi Experts, How to sepearate the list digit with letters : with a space from where the letters begins, or other words from where the digits ended. file 52087mo(enbatl) 52049mo(enbatl) 52085mo(enbatl) 25051mo(enbatl) The output should be looks like: 52087 mo(enbatl) 52049... (10 Replies)
Discussion started by: rveri
10 Replies

5. Shell Programming and Scripting

Need help putting output on one line

Good afternoon, I have been searching the web, and these forums for help. I will try my best to explain the issue, and what my desired results are. I am doing queries in MYSQL, and need the output to be sent to a file. That file needs to have things with the same ID on the same line. To... (14 Replies)
Discussion started by: brianjb
14 Replies

6. Shell Programming and Scripting

new line after specific number character

Hi All, I have input file like this: input1: ( 1083479)=T 158V 1798, T 391V 1896,T 1138V 2273,T 1547V 2477,T 2249V 2917,T 3278V 3234,T 4152V 3495,T 5500V 3631, ( 1083501)=T 181V 1851, T 459V 1954,T 810V 2141,T 1188V 2372,T 1638V 2696,T 2731V 3124,T 4799V 3640,... (5 Replies)
Discussion started by: attila
5 Replies

7. HP-UX

How to remove new line character and append new line character in a file?

Hi Experts, I have data coming in 4 columns and there are new line characters \n in between the data. I need to remove the new line characters in the middle of the row and keep the \n character at the end of the line. File is comma (,) seperated. Eg: ID,Client ,SNo,Rank 37,Airtel \n... (8 Replies)
Discussion started by: sasikari
8 Replies

8. UNIX for Dummies Questions & Answers

How to read contents of a file from a given line number upto line number again specified by user

Hello Everyone. I am trying to display contains of a file from a specific line to a specific line(let say, from line number 3 to line number 5). For this I got the shell script as shown below: if ; then if ; then tail +$1 $3 | head -n $2 else ... (5 Replies)
Discussion started by: grc
5 Replies

9. UNIX for Dummies Questions & Answers

putting grep -c results number in a variable

I want to display "no results found" if a grep search of a name that the user inputs is not found anywhere in a certain file, Right now I have this, but doesn't seem to work. Im not sure what to change. read name results=grep -c $name file if ; then echo "No results found." exit... (1 Reply)
Discussion started by: busdude
1 Replies

10. Shell Programming and Scripting

Putting a character between two other characters?

I need to separate Pascal style identifiers (TheyLookLikeThis) into words separated by an underscore (_). I've tried sed 's//&_&/' but this won't work (obviously). I'd love some help. (4 Replies)
Discussion started by: Ilja
4 Replies
Login or Register to Ask a Question