sort file adding extra character


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sort file adding extra character
# 1  
Old 09-20-2010
sort file adding extra character

HI all
i have this script :
Code:
#!/bin/bash
sort /usr/tmp/"REPORT"$1 -o \
 /usr/tmp/"SREPORT"$1 -k 1,7 -S 150

end of script
now i'm doing this command :
Code:
ls -lsgt *REPORT*
4 -rw-r--r--       300 Sep 16 REPORT54784
4 -rw-r--r--       301 Sep 16 SREPORT54784

as you can see the sorted file as an extra character , which i cannot understand why

i'm using this command's syntax on other files , and the sorted and unsorted file , are in the same size ,
can someone help ?
thanks in advnaced
Naama


Moderator's Comments:
Mod Comment Please use code tags!

Last edited by Franklin52; 09-20-2010 at 06:54 AM..
# 2  
Old 09-20-2010
Can not understand your problem. Where is the extra character. Do you mean SREPORT ?

Your command will sort the file /usr/tmp/"REPORT"$ and write the output on /usr/tmp/"SREPORT"$1
# 3  
Old 09-20-2010
Can you please post the input and the expected output.
# 4  
Old 09-20-2010
Hi
what i meant is that the number of the characters in the file REPORT54784
are 300 , while in the SREPORT54784 the number of the characters are 301
i didn't mean to the name of the file .i can't display the input and output it's write that it's binary files.
please help
Thanks
# 5  
Old 09-20-2010
sort probably added a missing newline at the end.

Code:
$ printf 'z\na' > unsorted
$ sort unsorted > sorted
$ ls -l unsorted sorted | awk '{print $5, $9}'
4 sorted
3 unsorted
$ od -c unsorted 
0000000    z  \n   a                                                    
0000003
$ od -c sorted   
0000000    a  \n   z  \n                                                
0000004

Also, sort is a text utility. Don't be surprised if you observe odd behavior with arbitrary binary data.

Regards,
Alister

Last edited by alister; 09-20-2010 at 07:33 AM..
This User Gave Thanks to alister For This Post:
# 6  
Old 09-20-2010
Hi
i did your last commands which show exactly what you've posted.
$ od -c REPORT54784
0000000 z \n a
0000003
$ od -c SREPORT54784
0000000 a \n z \n
0000004
my problem is that i have a program which accept this file in constant size of the record.
can i always be sure that the addition will be newline ? and not some other character ?
and if so how can i overcome this problem since i want to keep the file in the same size , due to what i've wrote above.
thanks in advanced
Naama
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Adding an extra date column in UNIX file

Hi All, I have a file with only one column of data (without delimiter). For Ex: cat temp.txt 22055 21088 93840 30990 50990 50950 I want to insert an additional column with current date as value. So, i have used below command but didn't get the result as excepted. Could onyone over... (5 Replies)
Discussion started by: Suresh
5 Replies

2. Shell Programming and Scripting

Adding Extra Column in txt file base on Condition

HI Guys, I have below input. Output Base on Below Condition. 1> if forth column is empty and next coming line have same name with \es then add that column name on all rows 2>rest of all are es:vsDataEUtranCellFDD Input:- CCL01736 CCL01736_7A_1 es:vsDataEUtranCellFDD ... (3 Replies)
Discussion started by: pareshkp
3 Replies

3. Shell Programming and Scripting

Adding Extra Commas to a CSV file

Trying in this forum. Not sure if it is permitted.... but in need of help. Please find the requirements in the below link. https://www.unix.com/unix-dummies-questions-answers/191503-add-extra-commas-csv-file-2.html#post302665179 Thanks in Advance. (1 Reply)
Discussion started by: chillblue
1 Replies

4. Shell Programming and Scripting

Echo to file using SH without adding newline character

Hello! I am able to do this in bash, using: echo -ne HELLO > file.txt and then, 'HELLO' is written into file.txt without the newline character to be added in the end of the file. How is this possible to be done using sh instead of bash? If I try something similar is SH, then inside... (3 Replies)
Discussion started by: hakermania
3 Replies

5. Shell Programming and Scripting

post-Adding character for a text file

#################################################################### #NAME SL.NO TITLE SAL #################################################################### |RAGAV S S | 12358 | SALES EXECUTIVE| | 25000 |RAJU R B | 64253 | SALES EXECUTIVE| ... (5 Replies)
Discussion started by: manas_ranjan
5 Replies

6. Shell Programming and Scripting

Adding extra word from file1 to file2

I need to add a word from file1 to file2 accordinggly... file1 contains name of servers and file2 version of server I need that information in a single file so that the format is server_name : version I been trying but havent been able to figure out how to search for a file using sed... ... (14 Replies)
Discussion started by: eponcedeleonc
14 Replies

7. Solaris

Adding Extra Hard Disk

Hi Solaris users - I have an Ultra10 SPARC machine, with IIe processor. To prepare for the Solaris10 admin exam PartII I need to set up the metadb/mirroring in my machine, but do not know how to do this properly. I need this to practice the mirroring tasks. If anyone could help it would be... (3 Replies)
Discussion started by: patcom
3 Replies

8. UNIX for Dummies Questions & Answers

Sort file by character position

Hi! I need to sort file by certain column (column position from-to). I tried sort command, but it works wrong. Example: 0001 5214521 0148 6712145 I need to sort this 2 lines by values from position 9 to 12 (bold) Output: 0148 6712145 0001 5214521 Is there any way how to do this? (2 Replies)
Discussion started by: nadinnne
2 Replies

9. IP Networking

Adding an extra route to the ip routing table

In my college dorm, there is a file sharing network in the entire building. Problem is, there is only a manual for windows with the settings on how to connect... :mad: They say that you have to give the following command in cmd in windows: route add 172.16.71.0 mask 255.255.255.0... (2 Replies)
Discussion started by: Japie89
2 Replies

10. Shell Programming and Scripting

Adding a character in the beginning of every line in a .dat file

How can i add a character(#) in the beginning of every line in a .dat file (2 Replies)
Discussion started by: Cool Coder
2 Replies
Login or Register to Ask a Question