Solved

How to remove \240 character from the flat file using sed.

Posted on 2008-10-10
3
2,845 Views
Last Modified: 2013-12-26
How to clean up the \240 character from the file line by line ?
0
Comment
Question by:vishali_vishu
3 Comments
 
LVL 40

Expert Comment

by:omarfarid
ID: 22690733
requirement not clear, can you elaborate?
0
 
LVL 48

Accepted Solution

by:
Tintin earned 250 total points
ID: 22690833
Do you mean octal 240 character?

In which case you can do

sed "s/\0240//" file >file.new
0
 
LVL 7

Expert Comment

by:Murugesan Nagarajan
ID: 22921856
The following command:
      sed -i.bak 's/240/Murugesandins/'  fileName
creates the backup file with the file name as "fileName.bak"
Also the file "fileName" is getting updated.
########################################################################################
Regarding removals:
-------------------
Use the following command to remove the first occurence of "240" in each line
      sed -i.bak 's/240//'  fileName
Use the following command to remove all the occurences of "240" in each line
      sed -i.bak 's/240//g'  fileName

Use the following command to remove the first occurance of "\0240"
      sed -i.bak "s/\\\0240//" fileName
Use the following command to remove the first occurance of "\0240"
      sed -i.bak "s/\\\0240//g" fileName

Use the following command to replace the first occurance of "\0240" with "\"
      sed -i.bak 's/\0240//' fileName
Use the following command to replace all the occurances of "\0240" with "\"
      sed -i.bak 's/\0240//g' fileName
########################################################################################
Regarding replacements:
-----------------------
Use the following command to replace the first occurence of "240" in each line with murugesandins
      sed -i.bak 's/240/murugesandins/'  fileName
Use the following command to replace all the occurences of "240" in each line with murugesandins
      sed -i.bak 's/240/murugesandins/g'  fileName

Use the following command to replace the first occurance of "\0240" with murugesandins
      sed -i.bak "s/\\\0240/murugesandins/" fileName
Use the following command to replace the first occurance of "\0240" with murugesandins
      sed -i.bak "s/\\\0240/murugesandins/g" fileName

Use the following command to replace the first occurance of "\0240" with "\"
      sed -i.bak 's/\0240/murugesandins/' fileName
Use the following command to replace all the occurances of "\0240" with "\"
      sed -i.bak 's/\0240/murugesandins/g' fileName
########################################################################################                                    
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now