Breaking lines which contains more than 50 characters in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Breaking lines which contains more than 50 characters in a file
# 1  
Old 10-12-2012
Breaking lines which contains more than 50 characters in a file

Hi,

I have a file which contains many lines. Some of them are longer than 50 chars. I want to break those lines but I don't want to break words, e.g. the file
Code:
This is an exemplary text which should be broken aaaaaa bbbbb ccccc
This is the second line
This line should also be broken aaaaaaaaaaaaaaaaaaaaaa

Should be changed in this way:
Code:
This is an exemplary text which should be broken
aaaaaa bbbbb ccccc
This is the second line
This line should also be broken
aaaaaaaaaaaaaaaaaaaaaa

Thanks in advance
# 2  
Old 10-12-2012
Have a look at the man page of "fmt". "fmt -50" is probably what you want.

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
# 3  
Old 10-12-2012
Code:
fold -sw50 file

This User Gave Thanks to elixir_sinari For This Post:
# 4  
Old 10-12-2012
thank you very much
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with listing file name containing particular text and count of lines with 10 characters.

Hi, I've 2 queries. I need to list files which doesn't contain a particular text in the content. For example say, I need to list files which doesn't contain string "abc" from all files ending with *.bad. How can I do that? Also, I want to display number of lines in a file which has atleast... (2 Replies)
Discussion started by: Gangadhar Reddy
2 Replies

2. Shell Programming and Scripting

Replace first 3 characters in a unix file in all lines

Replace first 3 characters in a unix file (say replace "A&B" with "C&D") in all lines of the file. Need a sed or awk script to do this. Kindly help! -Kumar (4 Replies)
Discussion started by: vasan2815
4 Replies

3. UNIX for Dummies Questions & Answers

Breaking up a text file into lines

Hi, I have a space delimited text file that looks like the following: BUD31 YRI 2e-06:CXorf15 YRI 3e-06:CREB1 YRI 4e-06 FLJ21438 CEU 3e-07:ETS1 CEU 8e-07:FGD3 CEU 2e-06 I want to modify the text file so that everytime there is a ":", a new line is introduced so that the document looks... (3 Replies)
Discussion started by: evelibertine
3 Replies

4. Shell Programming and Scripting

Remove lines with non-chinese characters from xml file

Hi there, I'm looking for a way to remove all lines that don't contain chinese characters from an xml file. Example: http://pastebin.com/8KzSbCKe The result should be like this: http://pastebin.com/ZywXsNhx Only lines that don't contain chinese characters should be deleted. If theres a mix of... (3 Replies)
Discussion started by: g4rb4g3
3 Replies

5. Shell Programming and Scripting

File breaking

Hey, I have to take one CSV file and break into more files. Let's I have a file prices.csv and the data in the file like 1,12345 1,34567 1,23456 2,67890 2,77720 2,44556 2,55668 10,44996 based on the first column, I want to create files. in this example 1 is repeated three times... (12 Replies)
Discussion started by: bond2222
12 Replies

6. UNIX for Dummies Questions & Answers

Display only the first two characters of all the lines from a file.

how do i Display only the first two characters of all the lines from a file.? (1 Reply)
Discussion started by: ritusubash
1 Replies

7. Shell Programming and Scripting

Adding text to file on certain lines with(special characters)

I need to add "new lines" of text with special characters, to specific lines in the file. There are 3 modifications needed. Been testing 2 here without success. #!/usr/bin/perl use FileHandle; $file=FileHandle->new; $FILENAME="/opt/etc/usr/file.txt"; $file->open ("<$FILENAME") or die... (13 Replies)
Discussion started by: A4ron4perl
13 Replies

8. Shell Programming and Scripting

Breaking long lines into (characters, newline, space) groups

Hello, I am currently trying to edit an ldif file. The ldif specification states that a newline followed by a space indicates the subsequent line is a continuation of the line. So, in order to search and replace properly and edit the file, I open the file in textwrangler, search for "\r " and... (14 Replies)
Discussion started by: rowie718
14 Replies

9. Shell Programming and Scripting

Merge lines in Flat file based on first 5 characters

Hi I have the fixed width flat file having the following data 12345aaaaaaaaaabbbbbbbbbb 12365sssssssssscccccccccc 12365sssss 12367ddddddddddvvvvvvvvvv 12367 vvvvv Here the first column is length 5 second is length 10 third is length 10 if the second or third column exceeds... (3 Replies)
Discussion started by: Brado
3 Replies

10. Shell Programming and Scripting

Find lines greater than 80 characters in a file

Hi, Can anyone please give me the grep command to find all the lines in a file that exceed 80 columns Thanks, gubbala (8 Replies)
Discussion started by: mrgubbala
8 Replies
Login or Register to Ask a Question