|
Search Forums:
|
|||||||
| Forums | Register | Forum Rules | Linux and Unix Links | Man Pages | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
||||
|
||||
|
Code:
awk 'END { if ($0=="") print "New line found."; else print "No new line found." }' input_file |
| Sponsored Links | ||
|
|
|
#3
|
|||
|
|||
|
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
|
||||
|
||||
|
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
|
|||
|
|||
|
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
|
||||
|
||||
|
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
|
|||
|
|||
|
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 | ||
|
|
![]() |
| Tags |
| solaris, unix commands |
| Thread Tools | Search this Thread |
| 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 |
|
|