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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
sed remove last 10 characters of a line start from 3rd line minifish Shell Programming and Scripting 7 03-26-2008 01:42 PM
Spurious line feeds ajcannon Shell Programming and Scripting 2 10-29-2007 04:24 AM
Remove header(first line) and trailer(last line) in ANY given file madhunk Shell Programming and Scripting 2 03-13-2006 12:36 PM
line feeds in csv gowrish Shell Programming and Scripting 10 09-01-2005 12:04 PM
carriage return/line feeds pitstop Shell Programming and Scripting 4 11-24-2003 12:47 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 06-15-2005
vsk vsk is offline
Registered User
 

Join Date: Jun 2005
Posts: 3
Remove line feeds

Hi,

I have a fixed width flat file which has 1 as the first char and E as the last character. Some of the records have a carriage return /line feeds .
how do I remove them?

Let me know.

Thanks
VSK
Reply With Quote
Forum Sponsor
  #2  
Old 06-15-2005
Registered User
 

Join Date: Jun 2005
Posts: 5
You could use sed or the tr command to strip off the characters you don't want. Here is a simple tr example.

This would remove carriage returns:
Code:
% cat yourfile.txt | tr -d "\r"
This would remove line feeds:
Code:
% cat yourfile.txt | tr -d "\n"
This would remove both...
Code:
% cat yourfile.txt | tr -d "\n" | tr -d "\r"

Last edited by STiVo; 06-15-2005 at 02:39 PM.
Reply With Quote
  #3  
Old 06-15-2005
djp djp is offline
Registered User
 

Join Date: Apr 2005
Posts: 13
Just out of curiosity, how would you do that using sed?

Thanks,
djp
Reply With Quote
  #4  
Old 06-15-2005
vsk vsk is offline
Registered User
 

Join Date: Jun 2005
Posts: 3
Remove line feeds

Quote:
Originally Posted by STiVo
You could use sed or the tr command to strip off the characters you don't want. Here is a simple tr example.

This would remove carriage returns:
Code:
% cat yourfile.txt | tr -d "\n"
This would remove line feeds:
Code:
% cat yourfile.txt | tr -d "\r"
This would remove both...
Code:
% cat yourfile.txt | tr -d "\n" | tr -d "\r"

But that will remove the \n and \r whcih are found in the end of each line and I do not want to do that

Following is the example:

1abcdef E
1ghijk E
1kmijol E
1kfcldsa
cdsc;mE
1kcdmlms E

Here want to remove the carrriage return from the last but one line, since we need 1 as the first char and E as the last char
Reply With Quote
  #5  
Old 06-15-2005
Registered User
 

Join Date: Jun 2005
Posts: 5
Quote:
Originally Posted by djp
Just out of curiosity, how would you do that using sed?

Thanks,
djp
I guess the newlines would be tricky but the returns should be removable with..

cat infile.txt | sed 's/\r//g' > outfile.txt

Now you have me wondering....
Reply With Quote
  #6  
Old 06-16-2005
Registered User
 

Join Date: Jun 2005
Location: Bangalore , INDIA
Posts: 28
This might help

sed '/^$/d' infile.txt > outfile.txt

check it out....
Reply With Quote
  #7  
Old 06-16-2005
Bughunter Extraordinaire
 

Join Date: May 2005
Location: In the leftmost byte of /dev/kmem
Posts: 1,262
I think we misunderstood what the threadstarter wanted: The task is to concatenate all lines starting NOT with a "1" to the last line so that all lines start with a "1" and end with an "e":

source.file:
1 this line is ok E
1 This line starts ok
but continues E
1 here is the next line E

target.file:
1 this line is ok E
1 This line starts ok but continues E
1 here is the next line E

This can easily be accomplished by sed's "N" and "P" subcommands, which reads in the next line and print the whole pattern space respectively.

I could say "man sed", but I'd rather like to suggest reading Dale Doughertys fantastic book "sed & awk" from O'Reilly Publishing. He discusses exactly such cases as examples for setting up what he calls a "while..do loop in a sed-script".

bakunin
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 02:12 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0