Trouble reading [noeol] file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Trouble reading [noeol] file
# 1  
Old 04-12-2010
Trouble reading [noeol] file

cat can't show the last line of a file sftp transffered from Windows, because the last line is not ended with new line.
Vi can show all line with warning [noeol]

I can append blank line in order for cat to show all lines, But is there a command to do this without modifying the file?

Code:
 
> cat -A test1.txt 
a$
> echo "">>test1.txt 
> cat -A test1.txt 
a$
b$

# 2  
Old 04-12-2010
That's the exact behavior you'd see if the byte after 'b' is a carriage return. The cursor would be brought back over the 'b' and then the command prompt would overwrite the 'b', making it seem as if it was never printed. Although perhaps the -A option should cause the carriage return to print as ^M or \r (I don't know since my cat does not support that option).

What exactly is in test1.txt? Please paste the output of
Code:
od -cb test1.txt

Regards,
Alister
# 3  
Old 04-12-2010
Quote:
Originally Posted by alister
That's the exact behavior you'd see if the byte after 'b' is a carriage return. The cursor would be brought back over the 'b' and then the command prompt would overwrite the 'b', making it seem as if it was never printed. Although perhaps the -A option should cause the carriage return to print as ^M or \r (I don't know since my cat does not support that option).

What exactly is in test1.txt? Please paste the output of
Code:
od -cb test1.txt

Regards,
Alister
Code:
 
> od -cb test1.txt
0000000   a  \n   b
        141 012 142
0000003

BTW: I wan't to loop through each line to do something with "while read", It just missed the last line.
# 4  
Old 04-12-2010
The "while read" probably read the final line just fine, but it also hit the end of file since there was no newline at the end of it, thereby exiting the loop.

Code:
$ printf 'a\nb' > test1.txt
$ od -cb test1.txt 
0000000    a  \n   b                                                    
          141 012 142                                                    
0000003
$ while read line; do echo IN WHILE: $line; done < test1.txt ; echo AFTER WHILE: $line
IN WHILE: a
AFTER WHILE: b

You could try the following to ensure that the loop body executes if the final "line" isn't newline terminated:
Code:
$ while read line || [ "$line" ]; do echo $line; done < test1.txt
a
b

Regards,
Alister

Last edited by alister; 04-12-2010 at 02:40 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Trouble reading from a tab delimited excel file

So I have a file1.txt that is tab delimited: e.g. FIELD1 FIELD2 FIELD3 FIELD4 FIELD5 9545641 123 "Neighbor and Labrador,Canada" 54895 'CANADA' 9456465 456 "Neighbor and Labrador,Canada" 54893 'CANADA' 8746512 789 "Neighbor and... (11 Replies)
Discussion started by: dan139
11 Replies

2. Homework & Coursework Questions

Trouble with Shell Script Compressing file

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: You will create a shell script that performs the following action: Use a parameter to pass a file that... (5 Replies)
Discussion started by: Luvs2drnk
5 Replies

3. Shell Programming and Scripting

Trouble reading content of file from a variable

Hi , i have a parameter which has path of a file. Now i need to have another parameter with the content of that file. I tried the belwo script , can any one please help. I dont want to use cat command to read. Can we do it with out using cat command. while read line do... (9 Replies)
Discussion started by: Ravindra Swan
9 Replies

4. Shell Programming and Scripting

Trouble with catting a file

I have a perl script I am trying to modify and I cannot seem to get it to do right. I want it if the -l is ran with the script to cat the given file and then exit. my ( $help, $version, $list ); my $query = 0; my $default = ''; GetOptions( 'd|default=s' => \$default, 'q|query=s'... (3 Replies)
Discussion started by: bigbenn
3 Replies

5. Shell Programming and Scripting

Trouble with variable assignment and reading in shell scripting

Hi, I have an inputfile with some table names in it. For ex: t_arnge t_profl t_fac I need a script which reads the line one by one and need to assign to some dynamic variable. If to explain the above example: i need some a=table_name1 table_name1=t_arnge in first time and... (4 Replies)
Discussion started by: Ravindra Swan
4 Replies

6. UNIX for Advanced & Expert Users

Trouble with log file..

Hi guys, I have to filter out certain patterns from a log file (arerror.log, for those who know BMC Remedy). The problem is that the file is big, too big to be read properly. Filters aren't working properly on the file, and neither the entire contents are visible using more, or vi. I FTP'd it to... (9 Replies)
Discussion started by: raj_55555
9 Replies

7. Shell Programming and Scripting

Trouble with sed and ini file parsing

hi people, i'm having a hard time trying to extract a list of vars delimited by section inside a ini file ... let's consider this ini file : ; config file DESC = "channel synchro TGG01" DMM_VER = DMM23 PATH_FIFO = /users/tgg00/fifo QRT = BTS01.TGG.01.2 MODE_TRACE... (5 Replies)
Discussion started by: odium74
5 Replies

8. Shell Programming and Scripting

Trouble printing multiple lines to a new file

Hi, I'm trying to auto generate some php files with a default preamble at the top which is a block comment. The problem is that my output has no new lines and it looks like the output from "ls" is being printed after everyline This is my code #!/bin/bash read -d '' pre_amble... (1 Reply)
Discussion started by: racshot65
1 Replies

9. Shell Programming and Scripting

trouble with moving a file

Hi , I'm not so new to linux but very very rusty. Trying to migrate my solar / wind power web server from Windows XP runnning apache to linux. I have the first part of the ftp down as you can see below. I'm having a problem once I have identified the daily file. I'm not being very clear with my... (3 Replies)
Discussion started by: Mikey
3 Replies

10. Shell Programming and Scripting

how to know whether that file has eol or noeol before opening that file in VI editor

Hi, I want to check whether file has EOL or NOEOL before opening this file in VI editor. My file is very big its in terms of 15-20 MB. I am using ksh for this. When we opened the file in vi editor, normally at last line we are able to see whether this is eol or noeol file. But i does want... (1 Reply)
Discussion started by: HariRaju
1 Replies
Login or Register to Ask a Question