The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 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 01:17 PM
delete a line based on first character of the line borncrazy UNIX for Dummies Questions & Answers 2 12-06-2005 03: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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-20-2008
sunilbm78 sunilbm78 is offline
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?
  #2 (permalink)  
Old 02-21-2008
robotronic's Avatar
robotronic robotronic is offline Forum Advisor  
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
  #3 (permalink)  
Old 02-28-2008
sunilbm78 sunilbm78 is offline
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.
  #4 (permalink)  
Old 02-28-2008
robotronic's Avatar
robotronic robotronic is offline Forum Advisor  
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?
  #5 (permalink)  
Old 02-28-2008
sunilbm78 sunilbm78 is offline
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.
  #6 (permalink)  
Old 02-28-2008
robotronic's Avatar
robotronic robotronic is offline Forum Advisor  
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.
  #7 (permalink)  
Old 02-28-2008
sunilbm78 sunilbm78 is offline
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.
Sponsored Links
Closed Thread

Bookmarks

Tags
solaris, unix commands

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:37 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0