Removing cr,lf till number of fields are full


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing cr,lf till number of fields are full
# 8  
Old 12-04-2013
Sorry the error was for akshays code.

Corona688, I tried yours on the sample data and all worked fine. I then tried it on the real file, there are 70 columns/fields in the file. The file has 4688 real lines, when you do a wc -l it has 4876 lines because of the lines not being always 70 (cr, end of line etc before reaching 70 values). So when I ran your program it has only 3751 lines.

I will upload the real file.

Thanks,
Tim
# 9  
Old 12-04-2013
Quote:
Originally Posted by tampatim
Corona688, I tried yours on the sample data and all worked fine. I then tried it on the real file, there are 70 columns/fields in the file.
Show the data you have and the data you want, then, or nobody will be able to make this data work for you.
# 10  
Old 12-04-2013
added csv file (but its really pipe delimited)

Last edited by tampatim; 12-04-2013 at 05:20 PM..
# 11  
Old 12-04-2013
OK, that's what the input you have looks like, now, what does the output you want look like?

I can see my code is wrapping lines where you might not like, but if it didn't, it wouldn't be 70 columns. Your data seems more complicated than your explanation.
# 12  
Old 12-04-2013
The goal would be that I can load all lines in the file and that each column/field is delimited by a pipe and each row has exactly 70 col/fields. The data has embedded cr/lf/eol in it. It came from an xls.

Thanks,
Tim

---------- Post updated at 04:50 PM ---------- Previous update was at 04:46 PM ----------

and from the original xls, there are 4688 rows.
# 13  
Old 12-04-2013
Making progress. Spotted one big bug and tracking one subtler one.
# 14  
Old 12-04-2013
Okay, I never imagined that tr would do this:

Code:
$ echo "||||||||" | tr -s '\r\n' '||'

|

$

| is not listed in the input set, why would it delete it? But several versions of tr do this, I guess this is "normal". It removes empty records, ruining column counts... and if I don't use -s, you get two consecutive newlines counting as multiple records, which ruins it the other way, adding extra records.

Trying to figure out a tr-alternative which isn't as stupid.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Is there a UNIX command that can compare fields of files with differing number of fields?

Hi, Below are the sample files. x.txt is from an Excel file that is a list of users from Windows and y.txt is a list of database account. $ head -500 x.txt y.txt ==> x.txt <== TEST01 APP_USER_PROFILE USER03 APP_USER_PROFILE TEST02 APP_USER_EXP_PROFILE TEST04 APP_USER_PROFILE USER01 ... (3 Replies)
Discussion started by: newbie_01
3 Replies

2. Shell Programming and Scripting

Printing Number of Fields with the line number

Hi, How to print the number of fields in each record with the line number? Lets saw I have 3212|shipped|received| 3213|shipped|undelivered| 3214|shipped|received|delivered I tried the code awk -F '|' '{print NF}' This gives me ouput as 3 3 4 (5 Replies)
Discussion started by: machomaddy
5 Replies

3. Shell Programming and Scripting

Get the number of lines till I get line

Hi All, I have a file as below: abc.txt ****************************** * HEADER DESCRIPTION ****************************** *Supplier: Prism Customer: MNI -NIGERIA Quantity: 2 Type: PLUG-IN Profile: 70.00 *Subscription: Generic... (5 Replies)
Discussion started by: arunshankar.c
5 Replies

4. Shell Programming and Scripting

Count the number of fields in column

Hi I was going through the below thread https://www.unix.com/shell-programming-scripting/48535-how-count-number-fields-record.html I too have something similar requirement as specified in this thread but the number of columns in my case can be very high, so I am getting following error. ... (3 Replies)
Discussion started by: shekharjchandra
3 Replies

5. Shell Programming and Scripting

Number of fields handled by awk

Hi Gurus, Have a file seperated by "~" and no of fields is 104. When i try to run awk, it erros out. awk: record `B~A31~T24_STF~~~2009...' has too many fields Any idea how can i extract a specific filed with this many fields in a row. Kindly help (3 Replies)
Discussion started by: srivat79
3 Replies

6. Shell Programming and Scripting

awk sed cut? to rearrange random number of fields into 3 fields

I'm working on formatting some attendance data to meet a vendors requirements to upload to their system. With some help on the forums here, I have the data close. But they've since changed what they want. The vendor wants me to submit three fields to them. Field 1 is the studentid field,... (4 Replies)
Discussion started by: axo959
4 Replies

7. Shell Programming and Scripting

way to print all the string till we get a space and a number

Is there any way to print all the string till we get a space and a number and store it a variable for eg we have string java.io.IOException: An existing connection was forcibly closed by the remote host 12 All I want is to store "java.io.IOException: An existing connection was forcibly closed... (13 Replies)
Discussion started by: villain41
13 Replies

8. Shell Programming and Scripting

How to print lines till till a pattern is matched in loop

Dear All I have a file like this 112534554 446538656 444695656 225696966 226569744 228787874 113536566 443533535 222564552 115464656 225445345 225533234 I want to cut the file into different parts where the first two columns are '11' . The first two columns will be either... (3 Replies)
Discussion started by: anoopvraj
3 Replies

9. Shell Programming and Scripting

Removing LF and extracting two fields

I need some assistance, I am writing a script in bash. I want to do two things: 1/. I want to replace the LF at the end of the RFH  Ø  ¸MQSTR ¸ so I can process the file record by record using a while loop. 2/. I want to extract two fields from each record, they are identified with... (1 Reply)
Discussion started by: gugs
1 Replies

10. Shell Programming and Scripting

Removing certain fields from a file

Hi, I have a file namely 'inputs' The values inside the file are like this and seperated by a '|'. mani|21|CSE How can I extract the values from this file without the '|' symbol. Thanks in advance. (1 Reply)
Discussion started by: sendhilmani123
1 Replies
Login or Register to Ask a Question