Clean and keep line breaks


 
Thread Tools Search this Thread
Top Forums Programming Clean and keep line breaks
# 1  
Old 10-15-2012
Clean and keep line breaks

Hello,

I want to keep line spaces in comments but clean more then 2 after each.

Example:

Code:
  $sentence="This is my first sentence
  This will be in a new row
  This will be too in a new row but not separated with 3line breaks just with
   
  one
   
  ";

And i want to output just this:

Code:
  $sentence="This is my first sentence
  This will be in a new row
   
  This will be too in a new row but not separated with 3line breaks just with
  one
  ";

Please Help

Thanks in Advance

Last edited by Corona688; 10-15-2012 at 12:04 PM..
# 2  
Old 10-16-2012
First: From the way this is worded, I assume it is homework incorrectly filed in a non-homework forum.

Second: I don't see any "comments" in your input; I just see a quoted string.

Third: I'm not sure what you mean by "line spaces". I assume you're talking about empty lines (lines where the only character on the line is the <newline> terminating the line) or blank lines (lines where the only characters on the line are <space> and <tab> characters followed by the <newline> terminating the line). But, while you talk about removing "line spaces", your example adds an empty or blank line in one place and removes one in two other places.

This has probably been sitting here unanswered for almost a full day because we can't figure out what you want.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Removing line breaks inside a field

Hi all, I have a csv input file with total 60 fields and the fields are not enclosed with double quotes.One of the field(50th field) in this file has line breaks in it which results in the row getting split into multiple lines.This is causing my load(to table) to fail.I tried to enforce double... (3 Replies)
Discussion started by: Bobby_2000
3 Replies

2. Linux

Line breaks in mail spool

Hi, I have an issue with the line breaks in the mail spool- /var/mail/user1. I have set up a script to go through the mail spool on one of the users and parse some parts of the mail, however there doesn't seem to exist the regular line endings CR, LF or both in the lines and this is breaking my... (4 Replies)
Discussion started by: night_watcher
4 Replies

3. Shell Programming and Scripting

[BASH] read 'line' issue with leading tabs and virtual line breaks

Heyas I'm trying to read/display a file its content and put borders around it (tui-cat / tui-cat -t(ypwriter). The typewriter-part is a 'bonus' but still has its own flaws, but thats for later. So in some way, i'm trying to rewrite cat using bash and other commands. But sadly it fails on... (2 Replies)
Discussion started by: sea
2 Replies

4. HP-UX

After using @, line breaks for a particular user in shell

Dear Concern, When we using @ sign, line breaks for a particular user in shell. Please advise how to resolve from the problem in HP UX. tabs@tabsdb02:/ccbs/users/tabs$ cat /etc/passwd|grep tabs tabs:RdCgOsmKee7Ps:221:201::/ccbs/users/tabs:/usr/bin/ksh... (3 Replies)
Discussion started by: makauser
3 Replies

5. UNIX for Dummies Questions & Answers

Page breaks and line breaks

Hi All, Need an urgent solution to an issue . We have created a ksh file or shell script which generates 1 DAT file. the DAT file contains extract of a select statement . Now the issue is , when we are executing the ksh file , the output is coimng with page breaks and line breaks . We have... (4 Replies)
Discussion started by: Ayaskant
4 Replies

6. Shell Programming and Scripting

Questions on removing unexpected line breaks

I am a newbie in Linux and I am having trouble with a piece of data on hand. The source data is like a|b|c|d e|f|g |h i|j|k|l m|n|o |p 1|2|3|4 5|6|7| 8 a|b|c|d e|f|g|h For each line, there should be 4 fields separated by the "|", but unfortunately there are unexpected line breaks... (13 Replies)
Discussion started by: Nekki Basara
13 Replies

7. Shell Programming and Scripting

Remove line breaks after a match

I need to remove all line breaks in a document after a match, until there is a blank line. Example below, after the match "THE GREEN TABLE" remove line breaks until a blank line. Then, after the match "THE BLUE TABLE" do the same. Before: THE GREEN TABLE Lorem ipsum dolor sit amet,... (14 Replies)
Discussion started by: dockline
14 Replies

8. Shell Programming and Scripting

Help with wc and line breaks

Hi everyone, I have gone through the forum trying to find an answer to this question but was unsuccessful. I am hoping that someone can help me with this please. I am trying to get my script to recognise line breaks from a file and to give me a result for wc of each line. So basically, if you... (7 Replies)
Discussion started by: stargazerr
7 Replies

9. Shell Programming and Scripting

any better way to remove line breaks

Hi, I got some log files which print the whole xml message in separate lines: e.g. 2008-10-01 14:21:44,561 INFO do something 2008-10-01 14:21:44,561 INFO print xml : <?xml version="1.0" encoding="UTF-8"?> <a> <b>my data</b> </a> 2008-10-01 14:21:44,563 INFO do something again I want... (3 Replies)
Discussion started by: csmklee
3 Replies

10. UNIX for Dummies Questions & Answers

Newbie ? Need Help with If/Then & Line Breaks...

I hope this makes sense, but I need help with what is indicated with %%, below : A.) ####List active servers and send to file#### # ps -ef | grep jboss | grep sh | awk '{if ($14) {print $12;}else {print $11}}' | sort > /export/home/kthatch/script_results client302 client306 client309... (1 Reply)
Discussion started by: kthatch
1 Replies
Login or Register to Ask a Question