LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-31-2011, 02:34 AM   #1
polch
LQ Newbie
 
Registered: Sep 2010
Posts: 22

Rep: Reputation: 0
Filling text with fixed column width.


Hi.

I'm working on the integration of the sozi player (http://sozi.baierouge.fr/wiki/en:welcome) in dia (http://live.gnome.org/Dia).

The sozi player consist in appending java scripts and a style sheet in a svg doc. The set of java scripts are minified and raw copied in the svg.

For the dia integration i put the raw minified java scripts in a const string.

My problem is that i would like to split the long string on multiple lines. For example
Code:
char* sozi_script = "A_long_javascript_code_of_more_than_2000_chars";
would become
Code:
char* sozi_script = 
"A_long_javascript_"
"code_of_more_than_"
"2000_chars";
I've tried the "--line-break" option of the minifier (yuicompressor), the pr , the fold and the fmt command line. But in either case i will need to add the quote at the end and the beginning of the lines (so use sed or awk).

So i wonder if i could fill and format with sed only. I also would like to cut the text every 40 char for example in order to have every lines of the same length.

If someone has an idea, i would be pleased to learn it.

Thank you.

Paul.

Last edited by polch; 08-31-2011 at 10:47 AM. Reason: add the fold tool
 
Old 08-31-2011, 11:37 PM   #2
Kenhelm
Member
 
Registered: Mar 2008
Location: N. W. England
Distribution: Mandriva
Posts: 360

Rep: Reputation: 170Reputation: 170
This uses GNU sed.
'18' is the maximum number of characters which can be inside the quotes.
Code:
sed -r '/char\* sozi_script = /{
s/= /=\n/
:a
s/(.*\n".{18})([^"])/\1"\n"\2/
ta
}' file

char* sozi_script =
"A_long_javascript_"
"code_of_more_than_"
"2000_chars";
If the last line has the maximum number of characters then the semi-colon is appended to it rather than being put on the next line.
Code:
sed -r '/char\* sozi_script = /{
s/= /=\n/
:a
s/(.*\n".{23})([^"])/\1"\n"\2/
ta
}' file

char* sozi_script =
"A_long_javascript_code_"
"of_more_than_2000_chars";
 
Old 09-02-2011, 10:34 AM   #3
polch
LQ Newbie
 
Registered: Sep 2010
Posts: 22

Original Poster
Rep: Reputation: 0
Thank you for those solutions.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Column width in thread view off? Tinkster LQ Suggestions & Feedback 4 08-13-2011 01:34 AM
Import fixed-width column text document in OpenOffice.org Calc Marel Linux - Desktop 3 05-05-2008 03:23 PM
How to parse text file to a set text column width and output to new text file? jsstevenson Programming 12 04-23-2008 02:36 PM
column width for netstat,top,etc minm Linux - Newbie 4 12-06-2004 01:30 AM
loading from text file using column width spyghost Programming 5 11-03-2003 01:34 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration