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

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:

% cat yourfile.txt | tr -d "\r"

This would remove line feeds:

% cat yourfile.txt | tr -d "\n"

This would remove both...

% cat yourfile.txt | tr -d "\n" | tr -d "\r"

Just out of curiosity, how would you do that using sed?

Thanks,
djp

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

I guess the newlines would be tricky :rolleyes: but the returns should be removable with..

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

Now you have me wondering.... :confused:

This might help

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

check it out.... :cool:

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

awk ' {
printf $0
while (length ($0) && substr ($0, length ($0), 1) != "E") {
getline; printf $0
}
if (length ($0) == 0) print "E"; else print ""
}' infile > outfile

gnu sed

sed -e ':a' -e 's/\r//g; /[^E]$/{N; s/\n//; ta}'