Home Man
Search
Today's Posts
Register

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

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

« 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? Ravi.K UNIX for Advanced & Expert Users 4 04-22-2017 03:04 AM
Help to replace the string with special characters nikhil jain Shell Programming and Scripting 3 02-13-2015 07:16 AM
How to replace special characters? ken002 Shell Programming and Scripting 25 11-05-2012 09:10 AM
Replace special characters with Escape characters? laknar Shell Programming and Scripting 8 01-05-2012 11:40 PM
How to replace special characters in vi? rogerben Solaris 2 08-03-2011 05:53 AM
Replace new line with <br /> & escape special characters ted_chou12 Shell Programming and Scripting 2 02-07-2011 08:25 PM
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 09:01 PM.

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