The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


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

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

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 02-20-2008
Registered User
 

Join Date: Feb 2008
Posts: 6
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?
Reply With Quote
Forum Sponsor
  #2  
Old 02-21-2008
robotronic's Avatar
Can I play with madness?
 

Join Date: Apr 2002
Location: Italy
Posts: 370
Code:
awk 'END { if ($0=="") print "New line found."; else print "No new line found." }' input_file
Reply With Quote
  #3  
Old 02-28-2008
Registered User
 

Join Date: Feb 2008
Posts: 6
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.
Reply With Quote
  #4  
Old 02-28-2008
robotronic's Avatar
Can I play with madness?
 

Join Date: Apr 2002
Location: Italy
Posts: 370
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?
Reply With Quote
  #5  
Old 02-28-2008
Registered User
 

Join Date: Feb 2008
Posts: 6
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.
Reply With Quote
  #6  
Old 02-28-2008
robotronic's Avatar
Can I play with madness?
 

Join Date: Apr 2002
Location: Italy
Posts: 370
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.
Reply With Quote
  #7  
Old 02-28-2008
Registered User
 

Join Date: Feb 2008
Posts: 6
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.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
solaris

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 10:09 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0