The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to split special characters "|" using awk krishna9 Shell Programming and Scripting 3 05-22-2008 07:30 AM
perl split funciton - special character "/" deepakwins UNIX for Dummies Questions & Answers 5 02-08-2008 12:19 AM
Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" Lokesha UNIX for Dummies Questions & Answers 4 12-20-2007 01:52 AM
extran NUll character added after end of line "\n" arunkumar_mca UNIX for Dummies Questions & Answers 1 11-12-2007 01:23 PM
How to replace newline "\n" gsprince UNIX for Dummies Questions & Answers 5 06-09-2001 07:35 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-15-2007
caddyjoe77 caddyjoe77 is offline
Registered User
  
 

Join Date: Apr 2005
Posts: 40
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 (permalink)  
Old 08-15-2007
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,409
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

Closed Thread

Bookmarks

Tags
regex, regular expressions

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:48 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0