Awk not working due to missing new line character at last line of file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awk not working due to missing new line character at last line of file
# 1  
Old 05-07-2009
Awk not working due to missing new line character at last line of file

Hi,

My awk program is failing. I figured out using command
Code:
od -c filename

that the last line of the file doesnt end with a new line character.

Mine is an automated process because of this data is missing.
How do i handle this?

I want to append new line character at the end of last line in file if it is missing.
i tried doing this.
Code:
echo ,,,, >> file

thinking this will add a line the file.


Quote:
File
ABC,ABC,ABC,,,,
Instead this is appending to the last field of the last line.

I want
Quote:
File
ABC,ABC,ABC\n
where \n is new line character

Help is appreciated
# 2  
Old 05-07-2009
Code:
echo "" >> filename

Will add a new line character to the end of the file.

Code:
$ echo fred > fred
$ od -bc fred
0000000 146 162 145 144 012
          f   r   e   d  \n
0000005
$ echo "" >> fred
$ od -bc fred
0000000 146 162 145 144 012 012
          f   r   e   d  \n  \n
0000006
$

# 3  
Old 05-07-2009
Quote:
Originally Posted by TonyFullerMalv
Code:
echo "" >> filename

Will add a new line character to the end of the file.

Code:
$ echo fred > fred
$ od -bc fred
0000000 146 162 145 144 012
          f   r   e   d  \n
0000005
$ echo "" >> fred
$ od -bc fred
0000000 146 162 145 144 012 012
          f   r   e   d  \n  \n
0000006
$

Thankyou TonyFullerMalv
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

Missing First Line when using awk

Hi there, I was using the following awk statement but the first line is missing dirlist=(`ls summary*`); #list all the files in a directory and store them into a variable echo '<table border='1'>' echo '<tr><td>%windir%\fonts\*.* </td><td>' ; awk '/Successfully/ {P=0} P... (2 Replies)
Discussion started by: alvinoo
2 Replies

3. Shell Programming and Scripting

Honey, I broke awk! (duplicate line removal in 30M line 3.7GB csv file)

I have a script that builds a database ~30 million lines, ~3.7 GB .cvs file. After multiple optimzations It takes about 62 min to bring in and parse all the files and used to take 10 min to remove duplicates until I was requested to add another column. I am using the highly optimized awk code: awk... (34 Replies)
Discussion started by: Michael Stora
34 Replies

4. Shell Programming and Scripting

awk new line issue, saying string can't contain new line character

Hi , I am doing some enhancements in an existing shell script. There it used the awk command in a function as below : float_expr() { IFS=" " command eval 'awk " BEGIN { result = $* print result exit(result == 0) }"' } It calls the function float_expr to evaluate two values ,... (1 Reply)
Discussion started by: mady135
1 Replies

5. Shell Programming and Scripting

awk concatenate every line of a file in a single line

I have several hundreds of tiny files which need to be concatenated into one single line and all those in a single file. Some files have several blank lines. Tried to use this script but failed on it. awk 'END { print r } r && !/^/ { print FILENAME, r; r = "" }{ r = r ? r $0 : $0 }' *.txt... (8 Replies)
Discussion started by: sdf
8 Replies

6. Shell Programming and Scripting

command-line line 0: Missing yes/no argument

Hi Guys When I run the below command ssh -o 'PasswordAuthentication yes' -o 'PreferredAuthentications publickey' -i $HOME/.ssh/id_dsa Server_Name I found the below error ommand-line line 0: Missing yes/no argument Kindly help me to sort out Double post, continued... (0 Replies)
Discussion started by: Pratik4891
0 Replies

7. Solaris

Line too long error Replace string with new line line character

I get a file which has all its content in a single row. The file contains xml data containing 3000 records, but all in a single row, making it difficult for Unix to Process the file. I decided to insert a new line character at all occurrences of a particular string in this file (say replacing... (4 Replies)
Discussion started by: ducati
4 Replies

8. HP-UX

How to remove new line character and append new line character in a file?

Hi Experts, I have data coming in 4 columns and there are new line characters \n in between the data. I need to remove the new line characters in the middle of the row and keep the \n character at the end of the line. File is comma (,) seperated. Eg: ID,Client ,SNo,Rank 37,Airtel \n... (8 Replies)
Discussion started by: sasikari
8 Replies

9. Shell Programming and Scripting

reading a file inside awk and processing line by line

Hi Sorry to multipost. I am opening the new thread because the earlier threads head was misleading to my current doubt. and i am stuck. list=`cat /u/Test/programs`; psg "ServTest" | awk -v listawk=$list '{ cmd_name=($5 ~ /^/)? $9:$8 for(pgmname in listawk) ... (6 Replies)
Discussion started by: Anteus
6 Replies

10. UNIX for Dummies Questions & Answers

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? (10 Replies)
Discussion started by: sunilbm78
10 Replies
Login or Register to Ask a Question