deleting newline characters but not the "true" \n character


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting deleting newline characters but not the "true" \n character
# 1  
Old 08-15-2007
deleting newline characters but not the "true" \n character

hi, i have a file that has about 4500 rows. this was an old microsoft access databse and what i am trying to do is take out the old extra \n newline characters but not take out the "true" newline character. I will explain.


i was trying to write a regular expression, but that was not working so i thought PERL would be the best option. The collums are seperated by commas.

Here is the dataset that i am working against.

144,20050892.0, Replacement of IN-FOCUS projector-Bldg 123, Replace malfunctioning In-Focus projector with new one.,- In-Focus projectors are used to project slideshows and other pertinent data to fron mountred screens.

- Intermittent power up problem, kicks on and off. This project was originally in Sept 2001.
- Bulbs have been replaced when it does work it is barely readable.,Infocus LP 640 XGA LCD Multimedia Projector $1699 EA


www.infocus.com,2005-09-29 00:00:00,2005-10-29 00:00:00,Joe Blow user
my phone number 5551212,5,0,3,None,,1,2005-10-12 00:00:00,C

Pretty much i need to remove the extra \n newline characters without removing the end one. This is what the dataset should look like.

144,20050892.0, Replacement of IN-FOCUS projector-Bldg 123, Replace malfunctioning In-Focus projector with new one.,- In-Focus projectors are used to project slideshows and other pertinent data to fron mountred screens. - Intermittent power up problem, kicks on and off. This project as originally in Sept 2001. - Bulbs have been replaced when it does work it is barely readable.,Infocus LP 640 XGA LCD Multimedia Projector $1699 EA
www.infocus.com,2005-09-29 00:00:00,2005-10-29 00:00:00,Joe Blow user my phone number 5551212,5,0,3,None,,1,2005-10-12 00:00:00,C

The fist column, in this case is 144, and they are numbered sequentially. So the next one would be 145.

can i do this with standard UNIX regular expressions or would PERL be better?

Thanks
# 2  
Old 08-15-2007
This uses the sequence numbers to remove line breaks...
Code:
awk -F, 'NR==1{c=$1+1}$1!=c{printf "%s ",$0}$1==c{c++;printf "\n%s",$0}END{printf ORS}' file1 > file2

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

How newline character "^M" appeared in file?

I have two files. Diff and hexdump tell that they are identical. However vi shows windows newline characters "^M" in one of these files. How is this possible? (2 Replies)
Discussion started by: urello
2 Replies

2. Shell Programming and Scripting

finding the strings beween 2 characters "/" & "/" in .txt file

Hi all. I have a .txt file that I need to sort it My file is like: 1- 88 chain0 MASTER (FF-TE) FFFF 1962510 /TCK T FD2TQHVTT1 /jtagc/jtag_instreg/updateinstr_reg_1 dff1 (TI,SO) 2- ... (10 Replies)
Discussion started by: Behrouzx77
10 Replies

3. Shell Programming and Scripting

Delete characters from each line until meet character ":"

Hello, I have file that looks like this : 765327564:line1 94:line2 7865:line3 ..... 765322:linen I want to cut all the digits from the beginning of each line up to ":" character and to have everything like this : line1 line2 line3 ..... linen P.S : content of line1 ...... (8 Replies)
Discussion started by: black_fender
8 Replies

4. Shell Programming and Scripting

Using sed to find text between a "string " and character ","

Hello everyone Sorry I have to add another sed question. I am searching a log file and need only the first 2 occurances of text which comes after (note the space) "string " and before a ",". I have tried sed -n 's/.*string \(*\),.*/\1/p' filewith some, but limited success. This gives out all... (10 Replies)
Discussion started by: haggismn
10 Replies

5. UNIX for Dummies Questions & Answers

Match newline character "\n" in lex

Hi everyone! This is my very first post, sorry if I'm not posting in the right category. I'm trying to match a newline "/n" using lex/yacc. For example, print(9,'\n',8) should print 9 8 now do I write a regular expression to match exactly " '\n' " Thanks! (1 Reply)
Discussion started by: code21
1 Replies

6. Shell Programming and Scripting

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

7. UNIX for Advanced & Expert Users

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

8. UNIX for Dummies Questions & Answers

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

9. Shell Programming and Scripting

How to remove "New line characters" and "spaces" at a time

Dear friends, following is the output of a script from which I want to remove spaces and new-line characters. Example:- Line1 abcdefghijklmnopqrstuvwxyz Line2 mnopqrstuvwxyzabcdefghijkl Line3 opqrstuvwxyzabcdefdefg Here in above example, at every starting line there is a “tab” &... (4 Replies)
Discussion started by: anushree.a
4 Replies
Login or Register to Ask a Question