Unix-problem of New line character


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unix-problem of New line character
# 8  
Old 01-18-2012
hi balajesuri...


not getting exactly


if i am in vi editor then hoe can i write the code :%s/<ctrl+v+m>//g and press "ctrl, v, m" keys together .... at a time.


please help me to clear this?

2 ) and lastly do we need to save this file using :wq ??

---------- Post updated at 05:56 AM ---------- Previous update was at 05:53 AM ----------

hey got the point of ctrl M and ctrl v thanks...

---------- Post updated at 05:59 AM ---------- Previous update was at 05:56 AM ----------

I have tried the above code.... but i am getting error

error:- patteren not found: ^M Smilie

---------- Post updated at 06:11 AM ---------- Previous update was at 05:59 AM ----------

hey thanks a lot its working :-)
# 9  
Old 01-18-2012
In vi, type the following :%s/ at this point, press ctrl key, press v, release v, press m, release m and ctrl. Now continue the substitution command by further typing //g
# 10  
Old 01-19-2012
Hi,

i am able to run the above command successfully.

Code:
sed -i 'sed -i 's/^M//g' ps6.txt


--> if i type this command manually then its working.


but if i copy paste the above command in any other directory the its not working

and i want write the same code in shellscript like below

Code:
#!/bin/bash
clear
cd /home/user01/trial1
sed -i 's/^M//g' $inPutFile
rdCount=0;
while read myline

then the sed command is not working here. can you please give me the solution because each time i cant type this command..


Thanks

---------- Post updated at 06:38 AM ---------- Previous update was at 06:15 AM ----------

Its working thanks
# 11  
Old 01-19-2012
The longer-term solution is to always use Text mode FTP when transferring text files from a Microsoft platform to a unix platform. A Microsoft text file has every line terminated with two characters "carriage-return" then "line-feed", whereas a unix text file has every line terminated with one character "line-feed".

In your script a quick fix is to filter the input stream with "tr" to remove the unwanted carriage-return characters.

Code:
#! /bin/bash
clear
rdCount=0;
cat ps5.txt | tr -d '\r' | while read myline
do
  if [ -z "${myline}" ]; then
    echo "line is empty"
  else
   echo $myline
   let rdCount=$rdCount+1
  fi
done
echo "COUNT=$rdCount"

Not sure why you are posting the uncorrected script following your previous thread.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. Shell Programming and Scripting

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:- 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:- ... ... ... nawk -F"|" -v v1="${v_pno}"... (7 Replies)
Discussion started by: shekharjchandra
7 Replies

7. 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

8. Shell Programming and Scripting

New line character problem with ksh on Redhat Linux

Guys, I would like to discuss the problem I am seeing with echo “\n” statement in Redhat Linux Enterprise 5.3 version. I have a shell script that was written couple of years back for generic UNIX platforms based on ksh and was tested on Solaris 8,9,10 ; AIX 5.3 and Red Hat Enterprise Linux... (5 Replies)
Discussion started by: rijeshpp
5 Replies

9. Shell Programming and Scripting

Unix character set problem

Hi All, We are getting file into our unix box with multibyte characters. When we tried to view the file the record looks like this Frédéric Actually the data sent to us is Frédéric --> my locale charmap of unix is set to UTF8 only ... but still i am getting this problem. I... (6 Replies)
Discussion started by: sandeeppvk
6 Replies
Login or Register to Ask a Question