![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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" Code:
% cat yourfile.txt | tr -d "\n" Code:
% cat yourfile.txt | tr -d "\n" | tr -d "\r" Last edited by STiVo; 06-15-2005 at 02:39 PM. |
|
#3
|
|||
|
|||
|
Just out of curiosity, how would you do that using sed?
Thanks, djp |
|
#4
|
|||
|
|||
|
Remove line feeds
Quote:
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 |
|
#5
|
|||
|
|||
|
Quote:
cat infile.txt | sed 's/\r//g' > outfile.txt Now you have me wondering.... |
|
#6
|
|||
|
|||
|
This might help
sed '/^$/d' infile.txt > outfile.txt check it out.... |
|
#7
|
|||
|
|||
|
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 |
|||
| Google The UNIX and Linux Forums |