word wrap does not work


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers word wrap does not work
# 1  
Old 10-18-2012
word wrap does not work

I have an input file like this,
Code:
79     #---------------------------------------------------------------------------   80     #-  define generic contact   81     cat > ${NAGIOS_ETC}/contact-generic.cfg                             <<-'EOF'   82         define contact {   83                name                             contact-generic   84                register                         0   85                host_notification_commands       notify-host-by-email   86                host_notification_options        d,u,r   87                host_notification_period         24x7   88                host_notifications_enabled       1   89                service_notification_commands    notify-service-by-email   90                service_notification_options     w,u,c,r

I want my output to look like this...
Code:
79     #---------------------------------------------------------------------------   
80     #-  define generic contact   
81     cat > ${NAGIOS_ETC}/contact-generic.cfg                             <<-'EOF'   
82         define contact {   
83                name                             contact-generic   
84                register                         0   
85                host_notification_commands       notify-host-by-email   
86                host_notification_options        d,u,r   
87                host_notification_period         24x7   
88                host_notifications_enabled       1   
89                service_notification_commands    notify-service-by-email   
90                service_notification_options     w,u,c,r

# 2  
Old 10-18-2012
I don't understand. You have an input file that contains one line of 744 characters with no field or line delimiters other than a possible trailing <newline> at the end of the file. You want a program to split this into variable length lines and you title the thread "word warp does not work". Please explain what this has to do with word wrapping and what program it is that you believe is not working correctly.
# 3  
Old 10-18-2012
Is this a Windows-UNIX problem perhaps? If you open a UNIX text file in Microsoft Notepad it will look like that because notepad looks for carriage returns...
# 4  
Old 10-19-2012
Line delimiters are probably the line numbers which should go in the first columns of the line. If nothing else helps, you might try the following:

First, count the number of characters between successive instances of these line numbers. I suppose the "lines" in between to be of fixed length.

Then reformat the lines like this (replace "<number>" with the number you got):

Code:
sed -e ':a' -e '/^.\{<number+1>\}/ {s/^.\{<number>\}/&\n/;P;D;ta}' /path/to/infile

I hope this helps.

bakunin
# 5  
Old 10-20-2012
The ideas and questions stated above come to my mind as well. Pls explain your strange input file. Yet, some solutions:
Assuming lines of identical length (which they are not!), a fold -w<number> filemight do. On the other hand, assuming two or more digit new line indicators embedded in spaces, which is a fragile condition as numbers may appear anywhere in the text, try this
Code:
sed -r 's/ ([0-9]{2,} )/ \n\1/g' file

or, should your sed not support the -r option,
Code:
sed  's/ \([0-9]\{2,\} \)/ \n\1/g' file

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Uuencode a html file with word wrap

Hi, I have a file myfile.txt as seen below. Name Age Days --------- ------- -------- ABC 5 23 DEF 20 120 When i cat this file into a html file and send mail, I could see the file is opened as seen below. Name Age Days --------- ... (7 Replies)
Discussion started by: jayadanabalan
7 Replies

2. UNIX for Dummies Questions & Answers

Word Wrap .CSV Fils

Is there a generic method for applying word wrap to all cells for a .csv file? (6 Replies)
Discussion started by: jimmyf
6 Replies

3. UNIX for Dummies Questions & Answers

Word Wrap

When I cat a file that has several hundred characters in a line, the right hand side is truncated. How can I make everything displayed on my screen word wrap? (6 Replies)
Discussion started by: bsimon
6 Replies

4. UNIX for Dummies Questions & Answers

Find EXACT word in files, just the word: no prefix, no suffix, no 'similar', just the word

I have a file that has the words I want to find in other files (but lets say I just want to find my words in a single file). Those words are IDs, so if my word is ZZZ4, outputs like aaZZZ4, ZZZ4bb, aaZZZ4bb, ZZ4, ZZZ, ZyZ4, ZZZ4.8 (or anything like that) WON'T BE USEFUL. I need the whole word... (6 Replies)
Discussion started by: chicchan
6 Replies

5. UNIX for Dummies Questions & Answers

How to wrap words in vi?

I just typed several long lines into vi but I only want it to have 80 columns. How can I set this in vi? (3 Replies)
Discussion started by: guitarscn
3 Replies

6. Shell Programming and Scripting

Word wrap with sed

Hi, I got some timetable in a file but it is all mixed up like this 01:00 hgrtwhrt #104:00 tyergethr05:00 tqqrthd qrth #107:00 qhtrhqerth10:00 qerthrthqr qtrqthr qthrrt11:00 thqrthqrthrr rthgreth #212:00 trhrthrth14:00 wrthwrtwrqrthwrthwr #2116:00 trqhthtr: rthrthr17:00 rtwhtrhwrth rthwrt... (6 Replies)
Discussion started by: stinkefisch
6 Replies

7. AIX

Wrap Plug Test

Can someone show me on how to use DIAG command in doing a wrap plug test for fcs0 (FC Adapter)? (3 Replies)
Discussion started by: apra143
3 Replies

8. HP-UX

word wrap issue with grep

in my HP-Unix environment I continue to have issues seeing the whole file path when I do a grep Example: >ps -ef |grep test > /testpath/is/here/ should see: >ps -ef |grep test > /testpath/is/here/not/here/test Is there a setting to turn word wrap on/off? It works fine in our AIX... (4 Replies)
Discussion started by: bowtiextreme
4 Replies

9. Shell Programming and Scripting

replace word with using "sed" not work...

Hi, I have a xml text file with the following data, I would like replace F0</Number> to F</Number> only. i used sed to replace, but it not work!! anyone can help? <Number>11 20 03 22 23 21 91 00 F0</Number> <Number>12 20 03 20 99 21 91 20 F0</Number> <Number>10 21 03 21 78 21 92 27... (28 Replies)
Discussion started by: happyv
28 Replies

10. UNIX for Dummies Questions & Answers

word wrap in vi

I am using vi to edit shell scripts, but whenever I get to the end of the line it goes to the next line, and when I run the script it considers whatever was placed onthe next line a new command...I guess this has to do with word wrap- how do I continue to write on one line? (3 Replies)
Discussion started by: dangral
3 Replies
Login or Register to Ask a Question