Issue with a file that contains CRLF


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Issue with a file that contains CRLF
# 8  
Old 11-19-2009
In your original code, try adding a space after %s:
Code:
printf ("%s " , $9) >>"filelist.dat"

# 9  
Old 11-19-2009
the space does this to filelist.dat:

abc.csv
(space)def.csv

when i set this file to a variable i get:

echo $files_found:

(space)def.csvbc.csv
# 10  
Old 11-19-2009
Code:
$ cat pablo.sh
awk -F '[ \r]*' '
/^-/ { print $9 }
' x.log > filelist.dat

files_found=$(<filelist.dat)

echo Print without quotes
echo $files_found

echo Print withquotes
echo "$files_found"

$ ./pablo.sh        
Print without quotes
abc.csv def.csv
Print withquotes
abc.csv
def.csv
$

Jean-Pierre.
# 11  
Old 11-19-2009
copied everything you have done in your thread Jean Pierre and i get:

with quotes:

abc.csvdef.csv

I am struggling to understand why it is not doing this. I am usin g KSH
# 12  
Old 11-19-2009
Please, post the output of the following commands :
Code:
$ grep '^-' x.log | od -cx
$ od -cx filelist.dat

Jean-Pierre.
# 13  
Old 11-19-2009
please see below Jean Pierre:

out put from grep '^-' x.log | od -cx:

0000000 - r w x r w x - - - 1 n
2d72 7778 7277 782d 2d2d 2020 2031 206e
0000020 o - u s e r n o - g r o u p
6f2d 7573 6572 2020 6e6f 2d67 726f 7570
0000040 8 3 6 6 6 7 7 S e p 3 0
2020 3833 3636 3637 3720 5365 7020 3330
0000060 1 1 : 5 9 a b c . c s v \r \n
2031 313a 3539 2061 6263 2e63 7376 0d0a
0000100 - r w x r w x - - - 1 n
2d72 7778 7277 782d 2d2d 2020 2031 206e
0000120 o - u s e r n o - g r o u p
6f2d 7573 6572 2020 6e6f 2d67 726f 7570
0000140 5 1 2 O c t 7
2020 2020 2020 3531 3220 4f63 7420 2037
0000160 1 1 : 1 7 d e f . c s v \r \n
2031 313a 3137 2064 6566 2e63 7376 0d0a
0000200


output from od -cx filelist.dat

0000000 a b c . c s v \r d e f . c s v \r
6162 632e 6373 760d 6465 662e 6373 760d
0000020

Last edited by Pablo_beezo; 11-19-2009 at 06:57 AM..
# 14  
Old 11-19-2009
I don't understand why awk is using \r as the record separator.
Try to force the value of the record separator :
Code:
awk -F '[ \r]*' -v ORS='\n' '
/^-/ { print $9 }
' x.log > filelist.dat

Jean-Pierre.

Please use CODE tags in your posts.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Views How to replace a CRLF char from a variable length file in the middle of a string in UNIX?

My sample file is variable length, with out any field delimiters. It has min of 18 chars length and the 'CRLF' is potentially between 12-14 chars. How do I replace this with a space? I still want to keep end of record, but just want to remove these new lines chars in the middle of the data. ... (7 Replies)
Discussion started by: chandrath
7 Replies

2. Shell Programming and Scripting

Replace CRLF between pipe (|) delimiter with LF

Hi Folks! Need a solution for the following :- Source data ------------- 123|123|<CRLF><CRLF><CRLF>|321<CRLF> Required output ------------------ 123|123|<LF><LF><LF>|321<CRLF> <CRLF> represents carriage return <LF> represents line feed Being hunting high and low for a... (10 Replies)
Discussion started by: hishamzz
10 Replies

3. Shell Programming and Scripting

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 (14 Replies)
Discussion started by: qqp
14 Replies

4. Shell Programming and Scripting

Sorting file with CRLF within field, RS=$

OK below is what my sample file looks like. I need to sort by the Primary Key ie: {1:F01SAESVAV0AXXX0466020126} in the first record. Record seperator is $. I tried sort, but it completely messes it up. I am thinking I will need to use something like awk which understands the record seperator... (6 Replies)
Discussion started by: alfredo123
6 Replies

5. Shell Programming and Scripting

Appending CRLF to end of record

I need to append |\r\n (a pipe character and CRLF) at end of each record in Unix to all records where they are not already present. So first check for the presence of |\r\n and if absent append it else do nothing (3 Replies)
Discussion started by: abhilashnair
3 Replies

6. Homework & Coursework Questions

Convert ASCII Text, with CRLF

1. The problem statement, all variables and given/known data: write a script asciiFix.sh that takes an arbitrary number of file paths from the command line and carries out the same analysis on each one. If a file is not Windows ASCII, your script should do nothing to it. For each file that is... (7 Replies)
Discussion started by: kwatt019
7 Replies

7. 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

8. Programming

how to add CRLF support for CSV file generated in unix

Helo, my server side system is running on a redhat linux o.s. I have c program on the server which export list file into CSV format. now, I want that my program on server side is able to add support for CRLF(carriage return Line feed)into csv file format. so how do i write C program whcih... (3 Replies)
Discussion started by: amitpansuria
3 Replies

9. 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
Login or Register to Ask a Question