|
|
Question using sed replace text file \t
Hi All
System AIX 5.3 @ office /Cygwin @ home
Where RT is New Order number, I want replace "123" to new order
number. For testing third party program. How to handle regular
expression. Now,I am build some testing file.
When RT have \t ,(some text fields need to add special/meta character
on it. ) then add two \\ before it. But using sed, the result is not
ok, a <tab> found between = and {. I expected is \t . Do you know
what problem ?
#!/bin/ksh
# 2010/04/22
FN=abc.txt
FSED=abc.sed
# Add Backslash for & /
# Add backslash for $?,$#,$$,$@
# escape sequences \t,\n,\b,\r
RT="~!@#$%^\&**\/()_+-=\\\t{}[]|:\";'<>?,..\/\$*\$?\$#\$$\$@\|\|\$-\$!
\&\&>>>>!\&-2>\&(cmd;cmd)%job"
echo $RT
# using \\ before Escape Sequences
A="1234\\|5\\\t\\\t"
echo $A > $FN
echo "s/123/$RT/g" > $FSED
echo cat $FN
cat $FN
echo "\nUsing Sed repalce"
sed -f $FSED $FN
$ sed_meta.ksh
~!@#$%^\&**\/()_+-=\t{}[]|:";'<>?,..\/$*$?$#$$$@\|\|$-$!\&\&>>>>!\&-2>
\&(cmd;cmd)%job
cat abc.txt
1234\|5\t\t
Using Sed repalce
~!@#$%^&**/()_+-= {}[]|:";'<>?,../$*$?$#$$$@||$-$!&&>>>>!
&-2>&(cmd;cmd)%job4\|5
\t\t
Expected Output
==============
~!@#$%^&**/()_+-={}[]|:";'<>?,../$*$?$#$$$@||$-$!&&>>>>!&-2>&(cmd;cmd)
%job4\|5
\t\t
|
|
0
|
|
|
|
Reply
|
moonhkt (146)
|
4/22/2010 3:10:00 PM |
|
moonhkt wrote:
> System AIX 5.3 @ office /Cygwin @ home
>
> Where RT is New Order number, I want replace "123" to new order
> number. For testing third party program. How to handle regular
> expression. Now,I am build some testing file.
> When RT have \t ,(some text fields need to add special/meta character
> on it. ) then add two \\ before it. But using sed, the result is not
> ok, a <tab> found between = and {. I expected is \t . Do you know
> what problem ?
$ printf 'xyz' | sed -e 's/y/\t/' | od -ct x1
0000000 x \t z
78 09 7a
0000003
$ printf 'xyz' | sed -e 's/y/\\t/' | od -ct x1
0000000 x \ t z
78 5c 74 7a
0000004
$ sed --version
GNU sed version 4.1.5
[...]
RTFM.
PointedEars
|
|
0
|
|
|
|
Reply
|
Thomas
|
4/22/2010 11:27:15 PM
|
|
|
1 Replies
515 Views
(page loaded in 0.036 seconds)
|
|
|
|
|
|
|
|
|