HOW: Dealing with new line character Wiindows-vs-UNIX


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting HOW: Dealing with new line character Wiindows-vs-UNIX
# 1  
Old 05-04-2011
Java HOW: Dealing with new line character Wiindows-vs-UNIX

Hi
I am getting this similar below lines, by splitting one big file by using the code in my shell script

Line is:-
HTML Code:
111111111|  +.00|12/11/04|12/11/05|n
222222222|  +.00|12/11/05|12/11/06|n
333333333|  +.00|12/11/06|10/11/07|n
Code is:-
Code:
 
...
...
...
nawk -F"|" -v v1="${v_pno}" -v v2="${v_nid}" -v v3="${v_ipath}" '{
fn=v3 "/AAA_" (length($1)==2?"BBBB":"CCCCC") "_" v1 "_" v2 ".txt"
print > fn
}' ${v_ipath}/${v_pno}_spoolfile.txt
if [ $? -eq 0 ]
then
  sed 's/[ ]*$/\n/' ${v_ipath}/AAA_CCCCC_${v_pno}_${v_nid}.txt > ${v_ipath}/dummy.txt
  mv ${v_ipath}/dummy.txt ${v_ipath}/AAA_CCCCC_${v_pno}_${v_nid}.txt
...
...
...

But I want in following format
HTML Code:
111111111|  +.00|12/11/04|12/11/05|n
222222222|  +.00|12/11/05|12/11/06|n
333333333|  +.00|12/11/06|10/11/07|n
When I open the file in UNIX vi editor I am getting in required format i.e.
HTML Code:
111111111|  +.00|12/11/04|12/11/05|n
222222222|  +.00|12/11/05|12/11/06|n
333333333|  +.00|12/11/06|10/11/07|n
But if the same file I open in Windows I am getting in this format
111111111| +.00|12/11/04|12/11/05|n^222222222| .00|12/11/05|12/11/06|n^
333333333| +.00|12/11/06|10/11/07|n

In the place of ^ character I am getting box type character (Which I am not able to show in this editor, so I replaced with ^ symbol)

Any other good way of getting is highly appreciable
Regards
jc
# 2  
Old 05-04-2011
You probably need unix2dos and dos2unix.
Windows uses 0x0d0a as newline, while Unix uses 0x0a.
This User Gave Thanks to kevintse For This Post:
# 3  
Old 05-04-2011
Can anyone give some example on this unix2dos and dos2unix.
# 4  
Old 05-04-2011
Code:
# this command changes all 0x0a to 0x0d0a in your_file
unix2dos your_file

# 5  
Old 05-04-2011
Hi Kevintse
I have tried in following way

$ --> unix2dos file1.txt > file2.txt
could not open /dev/kbd to get keyboard type US keyboard assumed
could not get keyboard type US keyboard assumed

My Regional Options are set to Englidh (United States)

Do you think is there anyway I can use this 0x0a to 0x0d0a in my sed command

Regards

---------- Post updated at 11:56 AM ---------- Previous update was at 11:46 AM ----------

I have checked doing ftp the same file by setting as ASCII and mget. When I opened the file in Windows Notepad it showed in required format.

But is there a way of doing something similar in code while using sed or any other (As I am not doing ftp)
# 6  
Old 05-04-2011
Yea, you can use sed:
Code:
sed 's/$/\r/' infile > dos.txt

BTW, when you use unix2dos, you don't do
Code:
unix2dos file1.txt > file2.txt

you simply do
Code:
unix2dos file1.txt

unix2dos converts your files in place.
# 7  
Old 05-04-2011
Hi if my infile contains the data in following format

002010764| +.00|12/11/04|12/11/05|n^002010764| +.00|12/11/05|12/11/06|n^002010764| +.00|12/11/06|10/11/07|n^

Where ^ in red is a box type character
Then if I use your given command

Code:
 
sed 's/$/\r/' infile > dos.txt


I should get the rows in following format

002010764| +.00|12/11/04|12/11/05|n
002010764| +.00|12/11/05|12/11/06|n
002010764| +.00|12/11/06|10/11/07|n

When I tried this command
sed 's/$/\r/' infile > dos.txt

I got output something like this
002010764| +.00|12/11/04|12/11/05|nr^002010764| +.00|12/11/05|12/11/06|nr^002010764| +.00|12/11/06|10/11/07|nr^

^ is a box type character

PS:- The files generated from my shell script is placed in one of the folder in unix mount point. The splitted files are then accessed from Windows machine.
This is where when I open the splitted files I am getting this issue.

Also I tried the command
Code:
unix2dos file1.txt

Still the issue is same.

Thanks for looking into my problem.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Count specific character of a file in each line and delete this character in a specific position

I will appreciate if you help me here in this script in Solaris Enviroment. Scenario: i have 2 files : 1) /tmp/TRANSACTIONS_DAILY_20180730.txt: 201807300000000004 201807300000000005 201807300000000006 201807300000000007 201807300000000008 2)... (10 Replies)
Discussion started by: teokon90
10 Replies

2. Shell Programming and Scripting

Read character by character in line in which space is also included

Hi friend, I have one file , and i want to read that file character by character. I need this script in ksh. while using read option with -n1 am getting error. while read -n1 c read has bad option And if i am using below script, then if in a line has space like this ( Pallvi mahajan)... (10 Replies)
Discussion started by: pallvi_mahajan
10 Replies

3. Shell Programming and Scripting

Sed: delete on each line before a character and after a character

Hi there, A total sed noob here. Is there a way using sed to delete everything before a character AND after another character on each line in a file? The deletion should also delete the indicating characters(here: an opening and a closing parenthesis). The original file would look like... (3 Replies)
Discussion started by: bnbsd
3 Replies

4. Shell Programming and Scripting

Unix command to select first few characters and last character of a line

I have a huge file and I want to select first 10 charcters and last 2 characters of everyline and than will filter the unique line. I know, it must be easy bt I am new to unix scripting:) Ex. I have file as below and need to e3kbaird and last 2 characters. and than unique records. ... (3 Replies)
Discussion started by: Sanjeev Yadav
3 Replies

5. Shell Programming and Scripting

Unix-problem of New line character

Hi All, "Please read the below information carefully." i have tried the below code for counting the number of lines present in text file ignoring blank lines #! /bin/bash clear rdCount=0; while read myline do if ; then echo "line is empty" else echo $myline let... (10 Replies)
Discussion started by: aish11
10 Replies

6. UNIX for Dummies Questions & Answers

Need help removing last character of every line if certain character

I need help removing the last character of every line if it is a certain character. For example I need to get rid of a % character if it is in the last position. Input: aaa% %bbb ccc d%dd% Output should be: aaa %bbb ccc d%dd I tried this but it gets rid of all of the % characters.... (5 Replies)
Discussion started by: raptor25
5 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

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 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... (2 Replies)
Discussion started by: pinnacle
2 Replies
Login or Register to Ask a Question