How to avoid Newline character in generated text file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to avoid Newline character in generated text file?
# 1  
Old 04-26-2011
Java How to avoid Newline character in generated text file?

Hi All,
Just need small help in resolving the special new line character in generated output file.

In one of my shell script I am using following lines to get the spool file (i.e. sfile.txt) and
AAA_XXXX_p111_n222.txt
AAA_YYYY_p111_n222.txt

Here assuming
v_pnum="p111"
v_nid="n222"

HTML Code:
nawk -F"|" -v v1="${v_pnum}" -v v2="${v_nid}" -v v3="${v_opath}" '{
fn=v3 "/AAA_" (length($1)==2?"XXXX":"YYYY") "_" v1 "_" v2 ".txt"
print > fn
}' ${v_opath}/sfile.txt
 
if [ $? -eq 0 ]
then
sed 's/[ ]*$//' ${v_opath}/AAA_YYYY_${v_pnum}_${v_nid}.txt > ${v_opath}/temp.txt
mv ${v_opath}/temp.txt ${v_opath}/AAA_YYYY_${v_pnum}_${v_nkid}.txt
....
....
....
fi
With this I am getting 2 different files, but when I transfer this file to windows environment and open it in Notepad, I am getting a special new line character (similarly if I place this file in mountpoint folder i.e. having access in UNIX as well as Windows environment, same is the case)

Does anyone have idea like how to avoid this special new line character, or is there a better way of doing the above process.

Example of one of my output files, should look something like this as shown below (if I say Wordwrap no in notepad I get output in well formated)

HTML Code:
AA|222222222|111|222|03/21|2|cccccccccccccccccccccccccccccccccccccccccccccccccc|dddddddd          |eeeeeeeeeee                        |6666666|uuuuuuuuuu   |          |  |2011/03/21| | | |3|6666666|erertertertert|011|222|  | |          |                 |   |   |  | |          |                 |   |   |  | |          |                 |   |   |  |
AA|222222222|111|222|03/21|2|cccccccccccccccccccccccccccccccccccccccccccccccccc|dddddddd          |eeeeeeeeeee                        |6666666|uuuuuuuuuu   |          |  |2011/03/21| | | |3|6666666|erertertertert|011|222|  | |          |                 |   |   |  | |          |                 |   |   |  | |          |                 |   |   |  |
AA|222222222|111|222|03/21|2|cccccccccccccccccccccccccccccccccccccccccccccccccc|dddddddd          |eeeeeeeeeee                        |6666666|uuuuuuuuuu   |          |  |2011/03/21| | | |3|6666666|erertertertert|011|222|  | |          |                 |   |   |  | |          |                 |   |   |  | |          |                 |   |   |  |
AA|222222222|111|222|03/21|2|cccccccccccccccccccccccccccccccccccccccccccccccccc|dddddddd          |eeeeeeeeeee                        |6666666|uuuuuuuuuu   |          |  |2011/03/21| | | |3|6666666|erertertertert|011|222|  | |          |                 |   |   |  | |          |                 |   |   |  | |          |                 |   |   |  |
AA|222222222|111|222|03/21|2|cccccccccccccccccccccccccccccccccccccccccccccccccc|dddddddd          |eeeeeeeeeee                        |6666666|uuuuuuuuuu   |          |  |2011/03/21| | | |3|6666666|erertertertert|011|222|  | |          |                 |   |   |  | |          |                 |   |   |  | |          |                 |   |   |  |
But it is coming with special characters i.e. box like character at the end of each individual line, and the next logical line starting from the end of first line.

Regards
jc
# 2  
Old 04-26-2011
On the unix side, use the unix2dos (maybe called ux2dos) command on the file. Yur man page has an example of how to use it.

Those odd characters are Ascii 10 - unix newline. Windows uses CR/LF for carriage control
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Remove newline character from column spread over multiple lines in a file

Hi, I came across one issue recently where output from one of the columns of the table from where i am creating input file has newline characters hence, record in the file is spread over multiple lines. Fields in the file are separated by pipe (|) delimiter. As header will never have newline... (4 Replies)
Discussion started by: Prathmesh
4 Replies

2. Shell Programming and Scripting

How to remove newline character if it is the only character in the entire file.?

I have a file which comes every day and the file data look's as below. Vi abc.txt a|b|c|d\n a|g|h|j\n Some times we receive the file with only a new line character in the file like vi abc.txt \n (8 Replies)
Discussion started by: rak Kundra
8 Replies

3. Shell Programming and Scripting

Warning while sorting : A newline character was added to the end of file

Hi, I am trying to sort a csv file which has say 10 lines each line having a row size that is upto 30183 no. of COLUMNS (Row length = 30183). There is a LINE FEED (LF) at the end of each line. When I try to sort this file say, based on the second FIELD using the below command, sort -t ',' +1... (5 Replies)
Discussion started by: DHeisenberg
5 Replies

4. Shell Programming and Scripting

Script for removing newline character from file

Hi below is my file. cat input.dat 101,abhilash,1000 102,prave en,2000 103,partha,4 000 10 4,naresh,5000 (its just a example file) and my output should be: 101,abhilash,1000 102,praveen,2000 103,partha,4000 104,naresh,5000 below is my code cat input.dat |tr -d '\n' >... (6 Replies)
Discussion started by: abhilash_nakka
6 Replies

5. Shell Programming and Scripting

Appending newline character End of File

Hi Gurus, Need help. I'm a beginner in Unix. I have a requirement, need to add or append newline (\n) character in file. Sample Data: 1|Main|Test|~# 2|Main|Hello|~# 3|Main|Unix|~# 4|Main|File|~#Output: 1|Main|Test|~# 2|Main|Hello|~# 3|Main|Unix|~# 4|Main|File|~#\n -- append only... (13 Replies)
Discussion started by: Gouri Solleti
13 Replies

6. Shell Programming and Scripting

How to add newline character at end of file?

Hi All, I have following piece of code in UNIX C Shell script and I want to add one more command which can add newline at the end of file only if there is no newline character exists. foreach file (`ls $dd_PLAYCARD_EDI_IN`) if ( -f $dd_PLAYCARD_EDI_IN/${file} ) then cat -n... (4 Replies)
Discussion started by: jnrohit2k
4 Replies

7. Shell Programming and Scripting

Echo to file using SH without adding newline character

Hello! I am able to do this in bash, using: echo -ne HELLO > file.txt and then, 'HELLO' is written into file.txt without the newline character to be added in the end of the file. How is this possible to be done using sh instead of bash? If I try something similar is SH, then inside... (3 Replies)
Discussion started by: hakermania
3 Replies

8. Shell Programming and Scripting

How to check newline character in file?

Hi All, I have file with only one record,always be only one record. as like below. if that line contains newline end of the line..no need to add, if not just add the new line character. END OF FILE. ROW COUNT: 7 Please help me.. Thanks, (9 Replies)
Discussion started by: bmk
9 Replies

9. Shell Programming and Scripting

To remove the newline character while appending into a file

Hi All, We append the output of a file's size in a file. But a newline character is appended after the variable. Pls help how to clear this. filesize=`ls -l test.txt | awk `{print $5}'` echo File size of test.txt is $filesize bytes >> logfile.txt The output we got is, File size of... (4 Replies)
Discussion started by: amio
4 Replies

10. Shell Programming and Scripting

linking unix generated text file to html page

i am trying to link the text files that i generated from my shell script to an html page, to that i can view them using a browser, like internet explorer. i want to open the text files in html page when i enter a command to view the text file from the shell command. please could anyone help... (1 Reply)
Discussion started by: alexd
1 Replies
Login or Register to Ask a Question