Program to remove a pattern


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Program to remove a pattern
# 1  
Old 06-25-2008
Program to remove a pattern

Hi,

I want to remove all occurances of a character which follows a ^ symbol.

For ex:

This is a Test ^H^@^@^@^@^@^@ File used in VI. ^@^@^B^VDM-BM-$|M-^_M-F^AM-

In the above example, I should remove all characters which follows a ^.
(^H ^@ ^B ^V etc) and It should print This is a Test File used in VI

Is there a program or a cmd which I can use to do this?

Thanks & Regards
Sheshadri
# 2  
Old 06-26-2008
Quote:
Originally Posted by arsheshadri
Hi,

I want to remove all occurances of a character which follows a ^ symbol.

For ex:

This is a Test ^H^@^@^@^@^@^@ File used in VI. ^@^@^B^VDM-BM-$|M-^_M-F^AM-

In the above example, I should remove all characters which follows a ^.
(^H ^@ ^B ^V etc) and It should print This is a Test File used in VI

Is there a program or a cmd which I can use to do this?

Thanks & Regards
Sheshadri
Instead of above..solution for the following will help me.

I have to eliminate all characters between ^ and a space in a file.

Following lines -
Test ^ H^@^@^@^@^@^@^B^VDM-BM-$|M-^_M-F^AM- File1
Test^H^@^@^@^@^@^F^A^X^@^SM-s^TM-3M-G^A File2
Should be printed as below
Test File1
Test File2

I used sed '/^/,/ /d' command, but it is not working.

Please help me out.

Thanks & Regards
Sheshadri
# 3  
Old 06-26-2008
Hi,

Try this,

Code:
sed 's/\^.[^ ]*//g' input.txt

Regards,
Chella
# 4  
Old 06-26-2008
This looks like a binary format file when viewed with vi. Control codes are displayed as ^X . See "man ascii" for a table of these codes. For example "^@" is a null character (Hex 00).

Try visually comparing the output of:
strings filename | pg
cat -v filename | pg

If the ^X characters disappear in the "strings" version, the file contains control codes rather than actual "^" characters.

Accurate processing of a binary format file with text file programs such as "vi" , "sed" and "awk" is unlikely to produce a useful conversion. Your will need a proper program. If you just want to see an overview of the contents then "strings" will suffice.
# 5  
Old 06-26-2008
Thanks Chella,

sed 's/\^.[^ ]*//g' input.txt is working.

Is there a way to remove all characters from start of line till some character say ^.

Thanks & Regards
Shesha
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk to remove pattern and lines above pattern

In the awk below I am trying to remove all lines above and including the pattern Test or Test2. Each block is seperated by a newline and Test2 also appears in the lines to keep but it will always have additional text after it. The Test to remove will not. The awk executed until the || was added... (2 Replies)
Discussion started by: cmccabe
2 Replies

2. Shell Programming and Scripting

How to remove the lines with this pattern?

Hello everyone, I have a sample data like this: Glyma.10G051100 Glyma.02G036000 89.91 228 23 0 1 228 1 228 1e-78 294 Glyma.10G051100 Glyma.09G023700 87.28 228 29 0 1 228 1 228 1e-68 261 Glyma.10G285200 Glyma.20G103800 96.33 1663 55 4 1 1657 1 1663 0.0 2728 Glyma.10G285200 Glyma.05G093700 95.02... (2 Replies)
Discussion started by: nengcheng
2 Replies

3. UNIX for Advanced & Expert Users

How to remove a char before a pattern?

Hi I have a file where i want to remove a char before a specific pattern. exp: CREATE TABLE ( A, B, C, ----comma needs to be removed )AS SELECT A, B, C, ----comma needs to be removed FROM TABLE. So i want to delete the comma(,) after the C both ways.Pattern can be... (11 Replies)
Discussion started by: raju2016
11 Replies

4. Shell Programming and Scripting

Search a pattern in a line and remove another pattern

Hi, I want to search a pattern in a text file and remove another pattern in that file. my text file look like this 0.000000 1.970000 F 303 - 1.970000 2.080000 VH VH + 2.080000 2.250000 VH VH + 2.250000 2.330000 VH L - 2.330000 2.360000 F H + 2.360000 2.410000 L VL - 2.410000 ... (6 Replies)
Discussion started by: sreejithalokkan
6 Replies

5. Shell Programming and Scripting

Remove last pattern

I have a file with entries below. domain1.com.http: domain2.com.49503: I need this to be sorted like below. ie remove the patten after the last right-hand side . (dot). domain1.com domain2.com (7 Replies)
Discussion started by: anil510
7 Replies

6. Shell Programming and Scripting

Running a program multiple times to search pattern and assign structure

Hi all, I have a big file (n.txt) with following pattern: ATOM 1 N SER A 1 122.392 152.261 138.190 1.00 0.00 N ATOM 2 CA SER A 1 122.726 151.241 139.183 1.00 0.00 C TER ENDMDL ATOM 1 N SER A 1 114.207 142.287 135.439 1.00 0.00 ... (3 Replies)
Discussion started by: bioinfo
3 Replies

7. Linux

Perl program to print previous set of lines once a pattern is matched

Hi all, I have a text data file. My aim here is to find line called *FIELD* AV for every record and print lines after that till *FIELD* RF. But here I want first 3 to four lines for very record as well. FIELD AV is some where in between for very record. SO I am not sure how to retrieve lines in... (2 Replies)
Discussion started by: kaav06
2 Replies

8. Programming

how to check and remove leading zeroes from the buffer using c program

Helo , I m writing small module of c.on RHEL 4 I have one buffer (for e.g. buffer = "002" now I want to check whethere buffer contains leading zeroes and if it contains leading zeroes then I want to remove all leading zeroes ( i.e. if buffer = "002" then I want to make buffer = "2") how... (1 Reply)
Discussion started by: amitpansuria
1 Replies

9. Shell Programming and Scripting

How to remove a file with a particular pattern

Hi I have a list of files in a folder.I have a search pattern in the file name and i want to remove the file with that pattern.How can that be made List of files xxxxx.ID1.yyyyy.zzzzz yyyy.ID2.bbbbb.kkkkk xxxxx.ID1.yyyyy.zzzzz yyyy.ID4.bbbbb.kkkkk xxxxx.ID1.yyyyy.zzzzz... (2 Replies)
Discussion started by: sparks
2 Replies

10. Solaris

How to remove sudo program

How to completely uninstall sudo program? Thank u in advance (1 Reply)
Discussion started by: unitipon
1 Replies
Login or Register to Ask a Question