Remove newline & space


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Remove newline & space
# 1  
Old 10-03-2010
Remove newline & space

Can someone help me on this. I have a file that has a long line just like below. The long line keeps on being truncated to the next line (new line + space) for some reason. Basically, I just need to remove this problem. Hope somebody can help! Thanks!

INPUT FILE:
Code:
structuralObjectClass: javaContainer
creatorsName: administrator
createTimestamp: 20080221122414
javaReferenceAddress: #0#Enable#false
javaReferenceAddress: #1#LocalStoreDirectory#/opt/infra/script/bi
 n
javaReferenceAddress: #2#boolean#false
javaReferenceAddress: #3#URL#http://10.10.10.1:4215,http://10.10.10.
 2:4215
javaReferenceAddress: #4#randomize#true

OUTPUT FILE SHOULD BE:
Code:
structuralObjectClass: javaContainer
creatorsName: administrator
createTimestamp: 20080221122414
javaReferenceAddress: #0#Enable#false
javaReferenceAddress: #1#LocalStoreDirectory#/opt/infra/script/bin
javaReferenceAddress: #2#boolean#false
javaReferenceAddress: #3#URL#http://10.10.10.1:4215,http://10.10.10.2:4215
javaReferenceAddress: #4#randomize#true

# 2  
Old 10-03-2010
Code:
perl -0pe 's/\n //g' infile > outfile

# 3  
Old 10-03-2010
Code:
$ ruby -00 -ne 'puts $_.gsub(/\n+[[:space:]]+/,"")' file

# 4  
Old 10-04-2010
Code:
sed '
  :loop
  $b
  N
  s/\n\([^:]*\)$/\1/
  t loop
  P
  s/.*\n//
  t loop
 ' infile >outfile

(sets a branch target,
for last line print and exit,
read in a second line,
if there is no : in the second line, remove the linefeed to attach it to the first
and go back to see if there is another line to attach,
else write out the first line,
remove it from the buffer and
go back to see if there is another line to attach
)

Last edited by Scott; 10-04-2010 at 03:52 PM.. Reason: Please use code tags
# 5  
Old 10-04-2010
Code:
awk '{gsub("\n ","")}1' RS= file

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Concatenate integer and space/newline for cout in C++

I'm trying to print out integers and space/newline for a nicer output, for example, every 20 integers in a row with ternary operator. In C I could do it with:printf("%d%s",tmp_int, ((j+1)%20) ? "\t":"\n"); but could not figure out the equivalent in C++: cout << ((j+1)%20)?... (4 Replies)
Discussion started by: yifangt
4 Replies

2. Shell Programming and Scripting

Replace space by newline error

Hello I have had a requirement where I need to move data to a new line based on a text .So basically as soon as it encounters :61: it should move to a new line Source Data : :61:D100,74NCH1 :61:D797,50NCH2 :61:D89,38NCHK2 :61:D99,38NCHK12 :61:D79,38NCHK22 :61:D29,38NCHK5 Target Data... (11 Replies)
Discussion started by: kamijia83
11 Replies

3. Shell Programming and Scripting

Replace 3rd occurance of SPACE with newline

I have file with SQL output as 0001 firstname1 lastname1 0002 firstname2 lastname2 0003 firstname3 lastname3 0004 firstname4 lastname4 Expected output : 0001 firstname1 lastname1 0002 firstname2 lastname2 0003 firstname3 lastname3 0004 firstname4 lastname4 Let me know if this can... (9 Replies)
Discussion started by: sameermohite
9 Replies

4. Shell Programming and Scripting

Newline to space code removes 0 from the first line

I am having a peculiar problem. First I run the code below to append 0 at the start of each line in some hundreds of files that I have in a directory. These files have each word in a newline. for f in *.dat; do echo "0" > tmpfile cat $f >> tmpfile mv tmpfile $f done Then I run this... (7 Replies)
Discussion started by: shoaibjameel123
7 Replies

5. UNIX for Advanced & Expert Users

Need to remove leading space from awk statement space from calculation

I created a awk state to calculate the number of success however when the query runs it has a leading zero. Any ideas on how to remove the leading zero from the calculation? Here is my query: cat myfile.log | grep | awk '{print $2,$3,$7,$11,$15,$19,$23,$27,$31,$35($19/$15*100)}' 02:00:00... (1 Reply)
Discussion started by: bizomb
1 Replies

6. Shell Programming and Scripting

Replace newline character between a double quotes to a space

Hi Guys, I have a file with content as below aj.txt "Iam allfine" abcdef abcd "all is not well" What I'm trying to say is my data has some new line characters in between quoted text. I must get ride of the newline character that comes in between the quoted text. output must be:... (8 Replies)
Discussion started by: ajahuja
8 Replies

7. Shell Programming and Scripting

Using sed I want to replace space by newline

Input: -------------------------- 123asd 456sdasda 789a ------------------------- output wanted: --------------------- 123asd 456sdasda 789a ---------------------- I want this by sed in simple way please help (I know by: tr ' ' '\n' < inputfile )I want it by sed only (5 Replies)
Discussion started by: RahulJoshi
5 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

how to remove all tabs and newline (\n)

how to remove all tabs and newline (\n) from the exicting file (2 Replies)
Discussion started by: pvr_satya
2 Replies

10. UNIX for Advanced & Expert Users

newline character, space and tab after a string

no problem (6 Replies)
Discussion started by: angelina
6 Replies
Login or Register to Ask a Question