end of line issue


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting end of line issue
# 1  
Old 10-30-2008
end of line issue

Hello,

I am getting few text files with no EOF ( or end-of-line ) which i need to fix using a command so that i can include it in a script. Now i'm fixing this issue by opening the file in "vi" editor and adding last line.

e.g.,

server1#wc -l temp.txt
9 temp.txt
server1#cat temp.txt
0830200422
0830200459
0830200462
0830200548
0830200716
0830200765
0830200809
0830200831
0830200836
0830200942server1#

This file actually has 10 numbers but showing as 9 lines and also notice prompt displayed at the end of last line.

Please suggest how to fix this? i guess "tr" would do here.


Thanks
Prvn
# 2  
Old 10-30-2008
EOF is determined by the filesystem. In DOS ASCII 26 serves as an EOF marker for MS-DOS text files. Not Unix.

Anyway, if "server" should always be alone on the last line try this
Code:
awk ' {  p=index($0, "server")
           if(p>2)
           { print substr($0,1,p-1)
              print substr($0, p)
            }
            else {
                print $0
            } 
        } '  inputfile > tmp.tmp
  mv tm.tmp inputfile

# 3  
Old 10-30-2008
Thanks for your reply Jim,

I'm not sure if i made myself clear on explaining the problem.

Problem is not with "server" prompt etc.(it's just an indication that prompt coming on the same line of the last one of the file)

Yes, the file received from a DOS/Windows System and is seen as only 9-lines by UNIX. That's the problem. I need to fix it so that ALL 10 lines can be read by UNIX system.


Thanks
Prvn
# 4  
Old 10-30-2008
Hammer & Screwdriver Can you give us the exact characters?

Perhaps
cat myfile | od -An -t dC -w10

This will create a 10-across representation of everything in the file, with the ASCII codes for the characters.
# 5  
Old 10-30-2008
awk strips carriage control then adds it by default in the print statement.
Assuming you don't have ^M (DOS carriage return char):
Code:
awk '1' inputfile > outputfile

adds carriage return to the last line... is that what you mean?
# 6  
Old 10-30-2008
Thanks Jim, Your solution worked great.

Thank joeyg - Your solution did not work and gave syntax errors.

usage: od [-bcCdDfFoOsSvxX] [-] [file] [offset_string]
od [-bcCdDfFoOsSvxX] [-t type_string]... [-A address_base] [-j skip] [-N count] [-] [file...]
# 7  
Old 10-30-2008
Tools intriguing...

Code:
> cat one.txt
Jim   101362  1492 Hugh     0101    P 1 
Kerry 040419  6091 Lost St  0101    F 1 
Matt  242424  48 Speedway Dr4343    F 1 

> cat one.txt | od -An -t dC -w10
   74  105  109   32   32   32   49   48   49   51
   54   50   32   32   49   52   57   50   32   72
  117  103  104   32   32   32   32   32   48   49
   48   49   32   32   32   32   80   32   49   32
   10   75  101  114  114  121   32   48   52   48
   52   49   57   32   32   54   48   57   49   32
   76  111  115  116   32   83  116   32   32   48
   49   48   49   32   32   32   32   70   32   49
   32   10   77   97  116  116   32   32   50   52
   50   52   50   52   32   32   52   56   32   83
  112  101  101  100  119   97  121   32   68  114
   52   51   52   51   32   32   32   32   70   32
   49   32   10

With the above example, I can see the 10 representing line-feed characters. And that is what I expect to see between lines, and at the very end.

Not sure what went wrong with your try. Perhaps cut/paste my string onto your system. Or, I am running bash on Solaris; maybe an issue or difference with your system.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Printing string from last field of the nth line of file to start (or end) of each line (awk I think)

My file (the output of an experiment) starts off looking like this, _____________________________________________________________ Subjects incorporated to date: 001 Data file started on machine PKSHS260-05CP ********************************************************************** Subject 1,... (9 Replies)
Discussion started by: samonl
9 Replies

2. Shell Programming and Scripting

With script bash, read file line per line starting at the end

Hello, I'm works on Ubuntu server My goal : I would like to read file line per line, but i want to started at the end of file. Currently, I use instructions : while read line; do COMMAND done < /var/log/apache2/access.log But, the first line, i don't want this. The file is long... (5 Replies)
Discussion started by: Fuziion
5 Replies

3. Shell Programming and Scripting

Adding tab/new line at the end of each line of a file

Hello Everyone, I need a help from experts of this community regarding one of the issue that I am facing with shell scripting. My requirement is to append char's at the end of each line of a file. The char that will be appended is variable and will be passed through command line. The... (20 Replies)
Discussion started by: Sourav Das
20 Replies

4. UNIX for Dummies Questions & Answers

vim copy line and paste at the beginning, middle, and end of another line

How would you do vim copy line and paste at the beginning, middle, and end of another line. I know yy copies the whole line and p pastes the whole line, but on its own separate line. Sometimes I would like to copy a line to the beginning, middle, or end of another line. I would think this would be... (3 Replies)
Discussion started by: cokedude
3 Replies

5. UNIX for Dummies Questions & Answers

How to specify beginning-of-line/end-of-line characters inside a regex range

How can I specify special meaning characters like ^ or $ inside a regex range. e.g Suppose I want to search for a string that either starts with '|' character or begins with start-of-line character. I tried the following but it does not work: sed 's/\(\)/<do something here>/g' file1 ... (3 Replies)
Discussion started by: jawsnnn
3 Replies

6. Shell Programming and Scripting

find a certain line and append text to the end of the line

After I create printer queues in AIX, I have to append a filter file location within that printers custom file. within lets say test_queue.txt I need to find the row that starts with :699 and then I need to append on the end the string /usr/local/bin/k_portrait.sh. Now I've gotten the sed... (2 Replies)
Discussion started by: peachclift
2 Replies

7. Shell Programming and Scripting

adding characters end of line where line begins with..

Hi all, using VI, can anyone tell me how to add some characters onto the end of a line where the line begins with certain charactars eg a,b,c,......., r,s,t,........, a,b,c,......., all lines in the above example starting with a,b,c, I want to add an x at the end of the line so the... (6 Replies)
Discussion started by: satnamx
6 Replies

8. Shell Programming and Scripting

Get the 1st 99 characters and add new line feed at the end of the line

I have a file with varying record length in it. I need to reformat this file so that each line will have a length of 100 characters (99 characters + the line feed). AU * A01 EXPENSE 6990370000 CWF SUBC TRAVEL & MISC MY * A02 RESALE 6990788000 Y... (3 Replies)
Discussion started by: udelalv
3 Replies

9. Shell Programming and Scripting

Copying x words from end of line to specific location in same line

Hello all i know it is pretty hard one but you will manage it all after noticing and calculating i find a rhythm for the file i want to edit to copy the last 12 characters in line but the problem is to add after first 25 characters in same line in other way too copy the last 12 characters... (10 Replies)
Discussion started by: princesasa
10 Replies

10. Shell Programming and Scripting

sed issue with end of line

Example, Trying to replace text to the end of a line. Text file looks like this PP= 4 PP= 412 PP= 425 I want to replace only the following line: PP= 4 with PP= 2 How can this be done with sed? (3 Replies)
Discussion started by: hanson397
3 Replies
Login or Register to Ask a Question