Shell Programming and Scripting

BSD, Linux, and UNIX shell scripting Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Replace special characters

replace characters special, special character

👤 Login to reply
 
Thread Tools Search this Thread Display Modes
    #1  
Old 12-22-2011
ratheeshjulk ratheeshjulk is offline
Registered User
 
Join Date: Jun 2011
Last Activity: 11 April 2017, 11:30 AM EDT
Posts: 46
Thanks: 19
Thanked 3 Times in 2 Posts
Replace special characters

I have a line ending with special character and 0
The special character is the field separator for this line
in VI mode the file will look like below, but while cat the special character wont display

i know the hexa code for the special character ^_ is \x1f and ascii code is
\0037,


Code:
000^_^_^_^_^_^_0.000000^_^_^_^_^_^_^_^_^_^_^_^_0^_0.000000^_^_^_^_0^_0^_^_^_0



I can filter these lines which is ending with ^_0 with the below command

Code:
grep `echo "\0037"`0$ filenam


Now my requirement is i want add one end delimiter to such lines.
simply i want replace the last ^_0with ^_0{}, where {} is the new sring i am going to add as an end delimeter


the whole file will look like this
Code:
30093354^_40^_1^_1^_615220181^_1324314123^_b0002
b00^_^_^_b0002
b0002/038513530400025^_2^_9^_3^_1324929600^_1^_1^_19.070000^_0.000000^_19.070000^_0.000000^_0.000000^_USD ^_1.000000^_USD ^_0^_1^_1^_1^_^_^_^_^_3^_^_2^_ ^_1324314123907^_^_^_^_0^_0.000000^_^_^_^_^_^_^_^_0^_0.000000^_^_^_^_0^_0^_^_^_0
68576101^_4^_1^_1^_628398181^_1323894124^_m1500
M15^_^_^_m1500
M1500/038513480015005^_2^_9^_3^_1324501200^_1^_1^_31.410000^_0.000000^_31.410000^_0.000000^_0.000000^_USD ^_1.000000^_USD ^_0^_0^_0^_0^_^_^_^_56^_3^_^_20^_ ^_1323894124565^_^_^_^_0^_0.000.000000^_^_^_^_^_^_^_^_^_^_^_^_0^_0.000000^_^_0^_0^_0^_0^_^_^_0

>

out put should be something like this

Code:
30093354^_40^_1^_1^_615220181^_1324314123^_b0002
b00^_^_^_b0002
b0002/038513530400025^_2^_9^_3^_1324929600^_1^_1^_19.070000^_0.000000^_19.070000^_0.000000^_0.000000^_USD ^_1.000000^_USD ^_0^_1^_1^_1^_^_^_^_^_3^_^_2^_ ^_1324314123907^_^_^_^_0^_0.000000^_^_^_^_^_^_^_^_0^_0.000000^_^_^_^_0^_0^_^_^_0{}
68576101^_4^_1^_1^_628398181^_1323894124^_m1500
M15^_^_^_m1500
M1500/038513480015005^_2^_9^_3^_1324501200^_1^_1^_31.410000^_0.000000^_31.410000^_0.000000^_0.000000^_USD ^_1.000000^_USD ^_0^_0^_0^_0^_^_^_^_56^_3^_^_20^_ ^_1323894124565^_^_^_^_0^_0.000.000000^_^_^_^_^_^_^_^_^_^_^_^_0^_0.000000^_^_0^_0^_0^_0^_^_^_0{}

>

---------- Post updated at 08:18 PM ---------- Previous update was at 08:21 AM ----------

I solved the issue, But for some reason i could'nt use the desired string '{}' but managed with ''

Code:
perl -i -ne 's;(\x1F)0\n;\x1F0\n;g;print;' file

Sponsored Links
👤 Login to reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to replace special characters in vi? rogerben Solaris 2 08-03-2011 05:53 AM
Using sed to replace special characters nimo Shell Programming and Scripting 5 08-12-2010 02:42 AM
Find and replace special characters in a file sujithchandra UNIX for Dummies Questions & Answers 2 10-24-2008 06:59 AM
Help with find and replace w/string containing special characters CAGIRL UNIX for Dummies Questions & Answers 4 10-07-2008 07:13 PM
Replace Special characters in a file solai UNIX for Dummies Questions & Answers 1 07-13-2006 10:36 AM



All times are GMT -4. The time now is 01:39 AM.

Unix & Linux Forums Content Copyright1993-2018. All Rights Reserved.
×
UNIX.COM Login
Username:
Password:  
Show Password





Not a Forum Member?
Forgot Password?