Removing carriage returns from multiple lines in multiple files of different number of columns


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing carriage returns from multiple lines in multiple files of different number of columns
# 1  
Old 06-07-2016
Removing carriage returns from multiple lines in multiple files of different number of columns

Hello Gurus,

I have a multiple pipe separated files which have records going over multiple Lines. End of line separator is \n and records going over multiple lines have <CR> as separator. below is example from one file.

Code:
1|ABC DEF|100|10
2|PQ
RS
T|200|20
3| UVWXYZ|300|30
4| GHIJKL|400|40

I am after the output as below

Code:
1|ABCDEF|100|10
2|PQRST|200|20
3|UVWXYZ|300|30
4|GHIJKL|400|40


I have tried various options mentioned in the forum but it doesn't seems to be working on records with on multiple lines on mutiple files in a directory

Any help would be appreciated.

Thans

DEV

Last edited by Don Cragun; 06-07-2016 at 10:56 PM.. Reason: Add CODE tags, again.
# 2  
Old 06-07-2016
Please, try:
Code:
perl -0pe 's/(?:\n|\s+)(\D)/$1/g' example.txt

or
Code:
perl -0pe 's/[\n\s]+(\D)/$1/g' example.txt

Output:
Code:
1|ABCDEF|100|10
2|PQRST|200|20
3|UVWXYZ|300|30
4|GHIJKL|400|40

# 3  
Old 06-08-2016
There do not seem to be <CR> characters present in the input file only newlines (\n) ?
# 4  
Old 06-08-2016
Wouldn't a mere tr -d $'\r' <file help?
# 5  
Old 06-08-2016
Hi
Aia :- How do use the Perl commands on Solaris. do you need to include something in the shell script for the Perl commands to work.

Scrutinizer :-There are <CR> in the file. Its just that I havent added it.

Thanks
# 6  
Old 06-08-2016
Could you provide a sample file that Contains CR's ?
# 7  
Old 06-08-2016
Hi Scrutinizer,

Thanks for your response but honestly even I don't have access to sample files as files are in test environment. If I have to test the commands provided by you all gurus, I will have to run the commands on our test environment.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Removing multiple lines from input file, if multiple lines match a pattern.

GM, I have an issue at work, which requires a simple solution. But, after multiple attempts, I have not been able to hit on the code needed. I am assuming that sed, awk or even perl could do what I need. I have an application that adds extra blank page feeds, for multiple reports, when... (7 Replies)
Discussion started by: jxfish2
7 Replies

2. Shell Programming and Scripting

Multiple carriage returns within quotation marks causing new lines in csv

There is a closed thread called "carriage returns within quotation marks causing new lines in csv" that I am unable to post to, so I am starting a new thread. The awk solution worked perfectly in most cases. We have some cases where there are multiple carriage returns within a single quoted... (9 Replies)
Discussion started by: Mary Roberts
9 Replies

3. Shell Programming and Scripting

Reading multiple values from multiple lines and columns and setting them to unique variables.

Hello, I would like to ask for help with csh script. An example of an input in .txt file is below, the number of lines varies from file to file and I have 2 or 3 columns with values. I would like to read all the values (probably one by one) and set them to independent unique variables that... (7 Replies)
Discussion started by: FMMOLA
7 Replies

4. Shell Programming and Scripting

TR not removing carriage returns

I have a CSV with carriage returns in place of newlines. I am trying to use tr to remove them, but it isn't working. Academic year,Term,Course name,Period,Last name,Nickname 2012-2013,First Semester,English 12,4th Period,Arnold,Adam 2012-2013,First Semester,English 12,4th Period,Adams,Jim... (1 Reply)
Discussion started by: nextyoyoma
1 Replies

5. Shell Programming and Scripting

Removing carriage return/line feeds on multiple lines

I would like to remove carriage returns/line feeds in a text file, but in a specific cadence: Read first line (Header Line 1), remove cr/lf at the end (replace it with a space ideally); Read the next line (Line of Text 2), leave the cr/lf intact; Read the next line, remove the cr/lf; Read... (14 Replies)
Discussion started by: tomr2012
14 Replies

6. Shell Programming and Scripting

Compare multiple files with multiple number of columns

Hi, input file1 abcd 123 198 xyz1:0909090-0909091 ghij 234 999 xyz2:987654:987655 kilo 7890 7990 xyz3:12345-12357 prem 9 112 xyz5:97-1134 input file2 abcd 123 198 xyz1:0909090-0909091 -9.122 0 abed 88 98 xyz1:98989-090808 -1.234 1.345 ghij 234 999 xyz2:987654:987655 -10.87090909 5... (5 Replies)
Discussion started by: jacobs.smith
5 Replies

7. UNIX for Dummies Questions & Answers

Removing Lines Shared by Multiple Files

Hey everyone, I have a question about comparing two files. I have two lists of files. The first list, todo.csv, lists a series of compounds my supervisor wants me to perform calculations on. The second list, done.csv, lists a series of compounds that I have already performed calculations on.... (2 Replies)
Discussion started by: Stuart Ness
2 Replies

8. Shell Programming and Scripting

splitting a huge line of file into multiple lines with fixed number of columns

Hi, I have a huge file with a single line. But I want to break that line into lines of with each line having five columns. My file is like this: code: "hi","there","how","are","you?","It","was","great","working","with","you.","hope","to","work","you." I want it like this: code:... (1 Reply)
Discussion started by: rajsharma
1 Replies

9. Shell Programming and Scripting

PERL: removing blank lines from multiple files

Hi Guru's , I have a whole bunch of files in /var/tmp that i need to strip any blank lines from, so ive written the following script to identify the lines (which works perfectly).. but i wanted to know, how can I actually strip the identified lines from the actual source files ?? my... (11 Replies)
Discussion started by: hcclnoodles
11 Replies

10. Shell Programming and Scripting

Removing carriage returns with sed

How do we delete all carriage returns after a particular string using sed inside a K Shell? e.g. I have a text file named file1 below: $ more file1 Group#=1 User=A Role=a1 Group#=2 User=B Role=a1 Role=b1 Group#=3 User=C Role=b1 I want the carriage returns to be delete on the... (12 Replies)
Discussion started by: stevefox
12 Replies
Login or Register to Ask a Question