a strange message when executing the sort command | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

a strange message when executing the sort command

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 04-25-2007
marwan marwan is offline
Registered User
 
Join Date: Mar 2007
Last Activity: 16 April 2009, 11:23 AM EDT
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
a strange message when executing the sort command

Dear all,
when I issue the command:
gunzip -c file.gz |sort
the command is executed normally and correctly but a message keeps appearing everytime I run the command:

the message:
sort: missing NEWLINE added at end of input file STDIN

Does anyone know what is the meaning of this message?
Thanks in advance
Sponsored Links
    #2  
Old 04-25-2007
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
 
Join Date: Dec 2003
Last Activity: 13 May 2013, 9:02 AM EDT
Location: Melbourne, Australia
Posts: 2,185
Thanks: 3
Thanked 24 Times in 23 Posts
It's doing exactly what it says - it's adding a newline to the end of your input file as one isn't there, e.g.

Code:
$ echo -n "foo" | sort
sort: warning: missing NEWLINE added at EOF
foo
$ echo "foo" | sort
foo

You can suppress this benign message by redirecting STDERR to /dev/null, or by appending a newline to your input file, e.g.:

Code:
$ ( gzip -dc ./file.gz; echo ) | sort
-or-
$ gzip -dc ./file.gz | sort 2>/dev/null

You can verify that the last line of your input file doesn't contain a newline with:

Code:
$ gzip -dc ./file.gz | tail -1 | od -c

Cheers,
ZB
Sponsored Links
    #3  
Old 04-27-2007
marwan marwan is offline
Registered User
 
Join Date: Mar 2007
Last Activity: 16 April 2009, 11:23 AM EDT
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Dear Zazzybob,
thanks so much for the information, but i am so new to unix, and I can't completely follow up with u. I need to understand the source of the problem, that is why the sort command is adding a new line at the end of the file.
and when i execute the command : gunzip -c file.gz |tail -1 , the result is the last two lines, not the last line only.
Thanks
    #4  
Old 04-27-2007
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 24 October 2014, 10:39 PM EDT
Location: NM
Posts: 10,251
Thanks: 283
Thanked 803 Times in 747 Posts
Unix files that us humans consider text, use ASCII 10 for carriage control - it's called a newline character.

Unzip the file.
Open the file in an editor, go to the end of the very last line and hit the return key on the keyboard. That will add a newline (\n) to the end of the file. Save the changed file. Re-zip it.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
linux sort command produces strange output ajb UNIX for Dummies Questions & Answers 3 08-11-2011 12:17 PM
Really strange unix message t01scra AIX 3 02-17-2011 10:18 AM
Sort command - strange behaviour miwinter UNIX for Advanced & Expert Users 16 05-29-2008 07:19 AM
Strange error message with regex test... fgilain Shell Programming and Scripting 4 05-31-2006 09:52 PM
ed strange error message frenki Shell Programming and Scripting 6 10-29-2004 06:00 AM



All times are GMT -4. The time now is 12:13 AM.