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
# 1  
Old 03-11-2017
Removing CRLF combo but not CR or LF when alone

What is the command or script to remove CRLF but only when joined?

Tried using below but removed all instances of either
cat a.txt | tr -d "\r\n" > b.txt

Last edited by rbatte1; 06-08-2017 at 04:04 AM.. Reason: Added CODE tags
# 2  
Old 03-11-2017
Quote:
Originally Posted by qqp
what is the command or script to remove CRLF but only when joined?

Tried using below but removed all instances of either
Code:
cat a.txt | tr -d "\r\n" > b.txt

Code:
perl -pe 's/\r\n//' a.txt > b.txt


Last edited by rbatte1; 06-08-2017 at 04:05 AM.. Reason: Retro-fit CODE tags to match edit on first post
# 3  
Old 03-11-2017
This didn't work. The new file was created but:

Instances of LF were changed to CRLF and original instances of CRLF were ignored.

Last edited by rbatte1; 06-08-2017 at 04:05 AM.. Reason: Joined broken lines
# 4  
Old 03-11-2017
Quote:
Originally Posted by qqp
This didn't work. The new file was created but:

Instances of LF were changed to CRLF and original instances of CRLF were ignored.
What you are saying is not possible with the command I suggested.
Please, post some of the original data.

Last edited by rbatte1; 06-08-2017 at 04:06 AM.. Reason: Retro-joined up broken lines to match edit in quoted post
# 5  
Old 03-11-2017
I've attached a sample. You'll see LF at the end of an appropriate line break, and CRLF within fields I want to remove.

thanks for the insights.
# 6  
Old 03-11-2017
Quote:
Originally Posted by qqp
I've attached a sample. You'll see LF at the end of an appropriate line break, and CRLF within fields I want to remove.

thanks for the insights.
strange, the only things I see "within fields" are ^I-s (in vi) which are TABs...
# 7  
Old 03-11-2017
Try:
Code:
awk '{sub(/^\n/,x)}1' RS='\r' ORS='\r' file

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