Replace special characters

Tags
replace characters special, shell scripts, special character

Login to Reply

 
Thread Tools Search this Thread
# 1  
Old 12-22-2011
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

Login to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Similar Threads More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to replace special characters? Ravi.K UNIX for Advanced & Expert Users 4 04-22-2017 04:04 AM
How to replace value of password tag in xml with blanks when special characters are there? saroopkris85 How to Post in the The UNIX and Linux Forums 7 10-27-2015 04:35 PM
Search special characters in a file and replace with meaningful text messages like Hello raka_rjit UNIX for Dummies Questions & Answers 2 08-11-2015 05:28 AM
Help to replace the string with special characters nikhil jain Shell Programming and Scripting 3 02-13-2015 08:16 AM
Replace special characters with backslash and character temp_user Shell Programming and Scripting 3 11-25-2014 12:47 AM
How to replace special characters? ken002 Shell Programming and Scripting 25 11-05-2012 10:10 AM
Replace special characters with Escape characters? laknar Shell Programming and Scripting 8 01-06-2012 12:40 AM
How to replace special characters in vi? rogerben Solaris 2 08-03-2011 06:53 AM
Replace new line with <br /> & escape special characters ted_chou12 Shell Programming and Scripting 2 02-07-2011 09:25 PM
Using sed to replace special characters nimo Shell Programming and Scripting 5 08-12-2010 03:42 AM
Single/Multiple Line with Special characters - Find & Replace in Unix Script r_sarnayak Shell Programming and Scripting 0 06-02-2010 03:34 AM
Replace special characters in multiple files - perl RMSoares Shell Programming and Scripting 1 09-01-2009 07:09 PM
Find and replace special characters in a file sujithchandra UNIX for Dummies Questions & Answers 2 10-24-2008 07:59 AM
Help with find and replace w/string containing special characters CAGIRL UNIX for Dummies Questions & Answers 4 10-07-2008 08:13 PM
Replace Special characters in a file solai UNIX for Dummies Questions & Answers 1 07-13-2006 11:36 AM
All times are GMT -4. The time now is 02:51 AM.

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





Not a Forum Member?
Forgot Password?