Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Search Forums:



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

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-20-2008
Registered User
 

Join Date: Feb 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Need to serach if a new line character exists on the last line in a file

I have a file in which I need to search if a new line character exists on the last line in the file. Please let me know how can I achieve it using Unix commands?
Sponsored Links
    #2  
Old 02-21-2008
robotronic's Avatar
Can I play with madness?
 

Join Date: Apr 2002
Location: Italy
Posts: 370
Thanks: 0
Thanked 0 Times in 0 Posts

Code:
awk 'END { if ($0=="") print "New line found."; else print "No new line found." }' input_file

Sponsored Links
    #3  
Old 02-28-2008
Registered User
 

Join Date: Feb 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
It is not working

I created 2 files one with new line character and other with no new line charcter. For both these files, it still gives the following message:

New line found.

Please help.
    #4  
Old 02-28-2008
robotronic's Avatar
Can I play with madness?
 

Join Date: Apr 2002
Location: Italy
Posts: 370
Thanks: 0
Thanked 0 Times in 0 Posts
What do you mean with newline character? A "\n"? An empty line?

What's the format of your file (dos/unix)? On which OS and shell?
Sponsored Links
    #5  
Old 02-28-2008
Registered User
 

Join Date: Feb 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
1. The file is on a Unix OS.

2. Unix Hardware configuration:
Sun Microsystems Inc. SunOS 5.9

3. I need to search for end of line character i.e. /n on the last line of this file.

Please let me know if you will need more information.
Sponsored Links
    #6  
Old 02-28-2008
robotronic's Avatar
Can I play with madness?
 

Join Date: Apr 2002
Location: Italy
Posts: 370
Thanks: 0
Thanked 0 Times in 0 Posts
Uhm... A bit complex but it should work:

Code:
tail -1 input_file | od -An -t oC -w1 | tail -1 | grep -c "012"

Returns 1 if newline found, otherwise 0.
Sponsored Links
    #7  
Old 02-28-2008
Registered User
 

Join Date: Feb 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
2 problems:
a. when the command is executed it specifies "usage" in the result and
b. Looks like it retruns a value '0' for both types of files.

Please see below:

sma2z@ianb1as1 [/apps/prodcopy/export/RW10X] $ --> tail -1 Alert_enuCPU18.0002.exp | od -An -t oC -w1 | tail -1 | grep -c "012"
usage: od [-bcCdDfFoOsSvxX] [-] [file] [offset_string]
od [-bcCdDfFoOsSvxX] [-t type_string]... [-A address_base] [-j skip] [-N
count] [-] [file...]
0

sma2z@ianb1as1 [/apps/prodcopy/export/RW10X] $ --> tail -1 Alert_enuCPU16.0001.exp | od -An -t oC -w1 | tail -1 | grep -c "012"
usage: od [-bcCdDfFoOsSvxX] [-] [file] [offset_string]
od [-bcCdDfFoOsSvxX] [-t type_string]... [-A address_base] [-j skip] [-N
count] [-] [file...]
0


Thanks for looking into my problem.
Sponsored Links
Closed Thread

Tags
solaris, unix commands

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
Removing last character from each line of file cjhancock Shell Programming and Scripting 17 08-29-2008 04:05 AM
How to add new line character at the end of a file DebianJ UNIX for Dummies Questions & Answers 5 05-07-2008 03:22 PM
Deleting end of line $ character in file bwrynz1 UNIX for Advanced & Expert Users 3 01-08-2008 12:17 PM
delete a line based on first character of the line borncrazy UNIX for Dummies Questions & Answers 2 12-06-2005 02:27 PM
How would I replace the 9th character of every line in a file? LordJezo Shell Programming and Scripting 5 09-01-2004 11:51 AM



All times are GMT -4. The time now is 03:57 AM.