Removing CRLF combo but not CR or LF when alone


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing CRLF combo but not CR or LF when alone
# 8  
Old 03-11-2017
the awk command produced the same issue..... bad CRLF remains and correct LF at line endings changed to CRLF.

what is needed is to remove the CRLF in mid-row, and the correct line endings remain (LF or CRLF, doesn't matter)

I'll add screen shots from notepad++
# 9  
Old 03-11-2017
screenshots attached
Removing CRLF combo but not CR or LF when alone-original-1-bad-crlfpng
Removing CRLF combo but not CR or LF when alone-original-1-line-endings-lfpng
Removing CRLF combo but not CR or LF when alone-revised-bad-crlfpng
Removing CRLF combo but not CR or LF when alone-revised-bad-line-endings-crlfpng
# 10  
Old 03-11-2017
Hum.... Let me see if I understand.... You want to remove CRLF if the next field/line start with a tab? Which will result in joining the lines?
Coule you also take a small sample of adjoining lines and upload the original and the desired files?

Last edited by vgersh99; 03-11-2017 at 01:34 PM..
# 11  
Old 03-11-2017
Wouldn't it be easier to correct the (line breaks in the) cells in your spread sheet program (CALC, EXCEL, etc ...) than having people in here puzzling over this undecipherable file? Shooting in the dark, try
Code:
awk '{while (sub (/\r$/,_)) {getline T; $0 = $0 T}} 1'  /tmp/mozilla/testdata.txt

# 12  
Old 03-11-2017
needs to be automated as its becoming a daily import to our db.


Simply put, I want to leave the LF marks untouched.... and remove all CRLF when CRLF are found together


thanks all
# 13  
Old 03-11-2017
The command:
Code:
awk '/\r$/ {printf("%s", substr($0, 1, length($0) - 1));next}1' file

will remove all <carriage-return><newline> character pairs from a file named file. It produces exactly the same output as the code RudiC suggested in post #11, but uses a slightly different approach to get there. If you want to try either of these on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk or nawk.

The screenshots you provided in post #9 do not provide any useful information to us. (At least not to me.)

Note that the file you uploaded in the file testdata.txt in post #5 contains lots of <carriage-return><newline> character pairs, but it does not contain any <carriage-return> characters that are not immediately followed by a <newline> character.
# 14  
Old 03-12-2017
If you want to keep the <CR> in the lines, this might do:
Code:
awk '/\r$/ {ORS=""} 1; {ORS=RS}'  /tmp/testdata.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Combo for text

Hello all, i need to extract a part from an API output. Imagine this is the output : "result": "result": i need to use only the "hello my name is Mike" in the second line, without " " how can i do that? Thanks in advance Kind Regards and congrats for the great forum. (2 Replies)
Discussion started by: Board27
2 Replies

2. Web Development

CRLF to LF PHP

So I have this PHP script that takes info from HTML form and saves the info to a txt file. Here is the code <?php $input = $_POST; $dateposted = date("m-d-Y-His"); $fp = fopen("/some/location/public_html/sh/$dateposted.txt", "w"); fwrite($fp, $input.).'&nbsp;'; fclose($fp);... (16 Replies)
Discussion started by: GroveTuckey
16 Replies

3. Shell Programming and Scripting

Issue with a file that contains CRLF

I have a nawk that reads in a log file and outputs a file that matches my search. IFS=" " while read record do `echo $record | nawk 'BEGIN { FS=" " } { type_record=substr($0, 1, 1); if (... (14 Replies)
Discussion started by: Pablo_beezo
14 Replies

4. Shell Programming and Scripting

grep, awk, nawk combo

I have 2 files: File1 "aa","server","001-9031234-001", File2 001-9031234-001|12345 Both files have many lines of text. Each line needs to be evaluated. I need to look at the value of the third field in File 1. Then look for that same value in File 2 and assign the value of Field 2... (5 Replies)
Discussion started by: scriptr2be
5 Replies

5. Shell Programming and Scripting

Add CRLF is probably simple!

I am building a script that will execute programs using records/fields in a file as arguments. Before I start testing that, I am working on reading the file properly and using printf to display the fields in the file. I used typeset to format my output. Now all I need is to figure out how to... (1 Reply)
Discussion started by: Skyybugg
1 Replies

6. UNIX for Dummies Questions & Answers

Modem/Sound combo

I just got yet another PI! yay! :D . one problem... the sound/modem card is not detected by the kernel or even by windows PnP! i dunno of any UNIX driverDB online, but if you could point me to one, it would be fantastic! (4 Replies)
Discussion started by: boris888
4 Replies
Login or Register to Ask a Question