The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Remove last character of a term Raynon Shell Programming and Scripting 6 03-20-2008 06:04 AM
How to remove extraneous character vsmurali UNIX for Dummies Questions & Answers 7 03-18-2008 12:57 PM
Need to serach if a new line character exists on the last line in a file sunilbm78 UNIX for Dummies Questions & Answers 10 02-29-2008 02:15 PM
Trying to remove single character from a line Iz3k34l UNIX for Dummies Questions & Answers 5 07-07-2007 01:29 PM
Remove Last Character of Line danhodges99 Shell Programming and Scripting 4 05-21-2003 09:30 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-10-2005
shihabvk shihabvk is offline
Registered User
  
 

Join Date: May 2005
Posts: 54
To remove new line character

Hi,
I am facing one interesting problem :
I have a file which contains data like this
459,|1998-11-047|a |b |c \n efg | d|e | \n
459,|1998-11-047|a \n c|b |c \n efg | d|e | \n
Basically what I have to do is , I have to remove all \n which is coming ( enclosed ) in between two pipes ( | ).. The red coloured only...
The problem I am facing is , when i try to do it using sed .. because of this \n , sed takes the entries after it as next record.

Could you please help me

Shihab
  #2 (permalink)  
Old 08-10-2005
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
Code:
sed -e 's#|\([^|][^|]*\)\\n\([^|][^|]*\)|#|\1\2|#g' file
  #3 (permalink)  
Old 08-12-2005
shihabvk shihabvk is offline
Registered User
  
 

Join Date: May 2005
Posts: 54
Thanks for your help vgersh99

But it is not working
I will explain my problem with an example

Here is the input file
$cat input.dat
|a|b
c|d|
|e|f|i|
|h|i|j|

and out put should be like this
$cat output.dat
|a|bc|d|
|e|f|i|
|h|i|j|

Here the first two lines have been joined since new line is not in between |

Thanks in advance
Shihab
  #4 (permalink)  
Old 08-12-2005
Unbeliever Unbeliever is offline
Registered User
  
 

Join Date: Jul 2005
Location: England
Posts: 183
perl -e 'while (<>) { if (! /\|$/ ) { chomp; } print ;}' input.dat > output.dat

should work assuming the correct end of line is always preceeded with a '|' character.

If you have trailing spaces or suchlike on the lines then it needs a little modification.
  #5 (permalink)  
Old 08-12-2005
jerardfjay jerardfjay is offline
Registered User
  
 

Join Date: Feb 2005
Posts: 146
use tr

Code:
tr -d '\n\' < file.dat
where file.dat

Code:
AFD|asdf|
asdf|ADF|
ASD|ASDF|ASDF|ASDFA|
and the output of the command is

Code:
AFD|asdf|asdf|ADF|ASD|ASDF|ASDF|ASDFA|
  #6 (permalink)  
Old 08-12-2005
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,206
Code:
# cat file.txt
|a|b
c|d|
|e|f|i|
|h|i|j|


sed 'N; s/\n[       ]*\([^|]\)/\1/g' file.txt
|a|bc|d|
|e|f|i|
|h|i|j|
  #7 (permalink)  
Old 08-18-2005
shihabvk shihabvk is offline
Registered User
  
 

Join Date: May 2005
Posts: 54
Thanks a loooooot!!!!!
My problem have been solved....

The Solution Suggested by Unbeliever is working fine....
When I tried with the solution by jerardfjay , it gives me the following error : Segmentation fault(coredump) .. Could you please tell me why ? I am using AIX 5.

The solution with sed by reborg is also working fine.. but it fails , if more that one \n is there in a single line. It appends the first with second..and so on... any way could you please explain the code.. if you don't mind

Thanks once again
Shihab
Sponsored Links
Reply

Bookmarks

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 08:23 AM.


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