While read line ignores the '\' in file content


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting While read line ignores the '\' in file content
# 8  
Old 11-01-2011
While read line loop writes \02 in file as ^B

Thanks. That got resolved. I noticed another issue with while loop
Code:
 
    while read -r line1
         do
                 echo $line1 > $wrkdir/datatemp

for \01 in $line1 , ^A is written in the output . \02 is ^B, \03 is ^C and so on
eg. abc\main\02Run is written as abc\main^BRun in the $wrkdir/datatemp file.
Can anyone explain that why or how to resolve?

Moderator's Comments:
Mod Comment Use code tags, please

Last edited by Prev; 11-01-2011 at 08:28 AM..
# 9  
Old 11-01-2011
Quote:
Originally Posted by Prev
Thanks. That got resolved. I noticed another issue with while loop
Code:
 
    while read -r line1
         do
                 echo $line1 > $wrkdir/datatemp

for \01 in $line1 , ^A is written in the output . \02 is ^B, \03 is ^C and so on
eg. abc\main\02Run is written as abc\main^BRun in the $wrkdir/datatemp file.
Can anyone explain that why or how to resolve?

Moderator's Comments:
Mod Comment Use code tags, please
what is your input file and how about contents?
# 10  
Old 11-03-2011
Dear ygemici,

Code:
if [ -s "$wrkdir/temp.$i" ]
        then
         while read -r line1
         do
                 echo $line1 > $wrkdir/datatemp
         done < $wrkdir/temp.$i
fi

content in temp.$i files is of following type :
A_DBOARD\MAIN\02RUN\RUNSURE_EEE
A_DBOARD\MAIN\03RUN\RUNSURE_EEE
....
Which is written in output file datatemp as
A_DBOARD\MAIN^BRUN\RUNSURE_EEE
A_DBOARD\MAIN^CRUN\RUNSURE_EEE
....
# 11  
Old 11-03-2011
Which is your OS?... If solaris, try using print -r $line1 >$wrkdir/datatemp instead of echo...
The above code works fine for me in Linux

--ahamed
# 12  
Old 11-03-2011
Quote:
Originally Posted by Prev
Dear ygemici,

Code:
if [ -s "$wrkdir/temp.$i" ]
        then
         while read -r line1
         do
                 echo $line1 > $wrkdir/datatemp
         done < $wrkdir/temp.$i
fi

content in temp.$i files is of following type :
A_DBOARD\MAIN\02RUN\RUNSURE_EEE
A_DBOARD\MAIN\03RUN\RUNSURE_EEE
....
Which is written in output file datatemp as
A_DBOARD\MAIN^BRUN\RUNSURE_EEE
A_DBOARD\MAIN^CRUN\RUNSURE_EEE
....
what is output after this.
Code:
$ od -c $wrkdir/temp.$i

# 13  
Old 11-04-2011
Thanks Ahamed, print -r worked fine for me.
uname -rs gave the version as
AIX 3

ygemici, the output of od -c is of the type :
Code:
0000220    P   ,       s   e   r   v   e   r       j   o   b  \n        
0000240    C   A   M   P   A   G   N   E 002   R   U   N   \   R   U   N
0000260    E   X   T   R   C   A   M   P   A   G   N   E   ,       s   e
0000300    q   u   e   n   c   e       j   o   b  \n                   C           
:
:
0000500    T   \   E   X   T   R   A   C   T   S   S   R   C   ,       s
0000520    e   r   v   e   r       j   o   b  \n           C   A   M   P
0000540    A   G   N   E 002   R   U   N   \   M   R   U   N   C   A   M
0000560    P   A   G   N   E   ,       s   e   q   u   e   n   c   e

Where ever there is 002 is where the 02 is replaced by ^B in the output file.

Thanks for your input.

Last edited by Franklin52; 11-04-2011 at 09:20 AM.. Reason: Please use code tags for data and code samples, thank you
# 14  
Old 11-04-2011
Quote:
Originally Posted by Prev
Thanks Ahamed, print -r worked fine for me.
uname -rs gave the version as
AIX 3

ygemici, the output of od -c is of the type :
Code:
0000220    P   ,       s   e   r   v   e   r       j   o   b  \n        
0000240    C   A   M   P   A   G   N   E 002   R   U   N   \   R   U   N
0000260    E   X   T   R   C   A   M   P   A   G   N   E   ,       s   e
0000300    q   u   e   n   c   e       j   o   b  \n                   C           
:
:
0000500    T   \   E   X   T   R   A   C   T   S   S   R   C   ,       s
0000520    e   r   v   e   r       j   o   b  \n           C   A   M   P
0000540    A   G   N   E 002   R   U   N   \   M   R   U   N   C   A   M
0000560    P   A   G   N   E   ,       s   e   q   u   e   n   c   e

Where ever there is 002 is where the 02 is replaced by ^B in the output file.

Thanks for your input.
i think,this character of seqs is interpreted as "Start of text(^B)" from your shell.
it(probably your ksh) reads "\ and 02" and "02" is equal "002" in octal.
so "002" chars is now like ^B (STX). and there is a backslash in front of its.
then this equal to "\^B".. \^B is a control character is predefined for specify "Start of text(^B)" on your terminal device interface
(like putty,securecrt,different ssh clients and really terms) and
actually these are defined in termcap, terminfo and curses(for ex python use this) and
as VT100+,VT102,VT125.Vt400,XtermXX as some standarts (like ANSI standard XXXXX) and
shells use these loads of this meanings to char sets (such as ASCII cntrol character sets [C0,C1,G0,G1..within the ranges-> 000 to 037 and 200 to 237 octal,and it varies to different character sets)

you can view some cchars for your term.
Code:
# stty -a

actually you can use echo "-E" but ksh does not support that..
as ahamed said,"print -r" is good way for prints their literal value while use read -r in ksh and ksh derivatives.

regards
ygemici
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

GREP function in ksh which ignores LINE Breaks

Hello I am using a grep command with two patterns in my KSH script. File has line breaks in it and both the patterns are in different lines. Here is the command grep -l 'RITE AID.*ST.820' natriter820u.20140914 Pattern1 - RITE AID Pattern2 - ST*820 I am not getting any results from... (24 Replies)
Discussion started by: Raghav Garg
24 Replies

2. How to Post in the The UNIX and Linux Forums

GREP function in ksh which ignores LINE Breaks

I am using a grep command with two patterns in my KSH script. File has line breaks in it and both the patterns are in different lines. Here is the command - grep -l 'RITE AID.*ST.820' natriter820u.20140914 Pattern1 - RITE AID Pattern2 - ST*820 I am not getting any results from this,... (3 Replies)
Discussion started by: Raghav Garg
3 Replies

3. Shell Programming and Scripting

cut the variable from the line and use it to find the file and read the content of that file

Hi, I am working on one script..I am having files in the below format file 1 (each line is separated with : delimeter) SPLASH:SPLASH:SVN CIB/MCH:MCH:SVN Now I want from file 1 that most left part of the first line will store in... (6 Replies)
Discussion started by: rohit22hamirpur
6 Replies

4. Shell Programming and Scripting

Read a text file and print the content..

hello all i request you to give the solution for the following problem.. I want read the text file.and print the contents character by character..like if the text file contains google means..i want to print g go goo goog googl google like this Using unix Shell scripting... ... (7 Replies)
Discussion started by: samupnl
7 Replies

5. Shell Programming and Scripting

How to read file and only output certain content

Hi - I have a file containing data like :- cn=tommy,cn=users,c=uk passwordexpirydate=20100530130623z cn=jane,cn=users,c=uk passwordexpirydate=20100423140734z cn=michael,cn=users,c=uk passwordexpirydate=20100331020044z I want to end up with a file that looks like:-... (6 Replies)
Discussion started by: sniper57
6 Replies

6. Shell Programming and Scripting

bash: read file line by line (lines have '\0') - not full line has read???

I am using the while-loop to read a file. The file has lines with null-terminated strings (words, actually.) What I have by that reading - just a first word up to '\0'! I need to have whole string up to 'new line' - (LF, 10#10, 16#A) What I am doing wrong? #make file 'grb' with... (6 Replies)
Discussion started by: alex_5161
6 Replies

7. Shell Programming and Scripting

read file content

i have one file abhi.txt its contents are home8/mc09ats/UnixCw/backup/file1 home8/mc09ats/file2 i want to read this content of file using while loop.. in this i want to seperate the content as follows path=home8/mc09ats/UnixCw/backup file=file1 echo path echo file can you... (1 Reply)
Discussion started by: AbhijitIT
1 Replies

8. Shell Programming and Scripting

Read a file content with awk and sed

Hello , I have huge file with below content. I need to read the numeric values with in the paranthesis after = sign. Please help me with awk and sed script for it. 11.10.2009 04:02:47 Customer login not found: identifier=(0748502889) prefix=(TEL) serviceCode=(). 11.10.2009 04:03:12... (13 Replies)
Discussion started by: rmv
13 Replies

9. Shell Programming and Scripting

read a file and use the content for mapping

help me pls.. :( i want to read a mapping file. Below is the content of my mapping file. 6221,189,SMSC1,OMC1,WAP1 6223,188,SMSC2,OMC2,WAP2 so when my program running msisdn="622130302310" while not EOF if substring($msisdn,1,4) == "6221" -- > "6221" read from the file then echo... (0 Replies)
Discussion started by: voidmain
0 Replies

10. Shell Programming and Scripting

How to read the content of the particular file from tar.Z without extracting?

Hi All, I want to read the content of the particular file from tar.Z without extracting. aaa.tar.Z contains a file called one.txt, I want to read the content of the one.txt without extracting. Please help me to read the content of it. Regards, Kalai. (12 Replies)
Discussion started by: kalpeer
12 Replies
Login or Register to Ask a Question