Help with Pattern Matching and replacement in Gz files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with Pattern Matching and replacement in Gz files
# 1  
Old 09-12-2014
Help with Pattern Matching and replacement in Gz files

Hi Techies,

I need a help in finding junk characters and remove them from a Datafile.

we have a file and it had crores of records like below

Code:
SGSN_MCC_MNC=01150

but sometime due to the issue with sending server we are getting some junk characters in the middle of data like below

Code:
SGSN_MCC_MNC=011;50
SGSN_MCC_MNC=011>60
SGSN_MCC_MNC=011/76
SGSN_MCC_MNC=011<89
SGSN_MCC_MNC=011"50
SGSN_MCC_MNC=011^50

we are not sure what kinda junk character would come in between the data.

can you please help me in getting rid of this junk character from this field?

i tried to write some script with "zgrep -c" but failed. please help.

Thanks a ton in Advance!!
# 2  
Old 09-12-2014
With the help of tr you can delete all characters not in a set of specified characters:
Code:
tr -dc '[A-Za-z0-9_\12]' <input >output

Don't forget to include the newline (\12), or all lines will be join to one single line.
# 3  
Old 09-12-2014
Help with Pattern Matching and replacement in Gz files

Thanks for the Reply, apparently it doesn't work as the file is .gz type.
# 4  
Old 09-12-2014
Code:
awk 'gsub(/\;|\>|\<|\"|\^|\//,X,$0)' file

# 5  
Old 09-12-2014
Quote:
Originally Posted by mahi_mayu069
Thanks for the Reply, apparently it doesn't work as the file is .gz type.
Then use
Code:
gzip -dc input.gz | tr -dc '[A-Za-z0-9_\12]' | gzip -c >output.gz

or
Code:
gzip -dc input.gz | tr -dc '[A-Za-z0-9_\12]' >output

if you want the output to be uncompressed.
# 6  
Old 09-13-2014
Thanks but neither of the suggestion don't work Smilie
# 7  
Old 09-13-2014
WHAT does not work? Post the (partial) output of the first part of the pipe; redirect it to a file and apply the tr command on that. Post that result as well.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pattern Matching and replacement

Hello Everybody, I need a help in the below pattern matching and replacement issue I have a file : emp.txt 21356 suresh 12/12/2012 23511 ramesh 11/06/2011 31456 biswajit 09/08/2013 53134 archan 06/02/2009 first field:- employee id, 2nd field is name and third field is date of joining ... (10 Replies)
Discussion started by: shellscripting
10 Replies

2. Shell Programming and Scripting

Removing files matching a pattern

I am on ubuntu 11.10 using bash scripts I want to remove all files matching a string pattern and I am using the following code find . -name "*$pattern*" -exec rm -f {} \;I have encountered a problem when $pattern is empty. In this case all my files in my current directory were deleted. This... (3 Replies)
Discussion started by: kristinu
3 Replies

3. UNIX for Dummies Questions & Answers

Script to list non matching files using pattern

Hi, I am trying to write a script that list down all the files that do not match the pattern My pattern will be like this "*.jpg|*.xml|*.sql". This pattern will be stored in a file. The script need to read this pattern from the file and delete the files that does not match this pattern. It... (7 Replies)
Discussion started by: meenavin
7 Replies

4. Shell Programming and Scripting

how to find files matching a pattern and zip

Hi, I want to find all directories matching given pattern in current directory and zip those files. I am trying to do somethign like this. But it is not working. for FNAME in $(find . -type d | grep './\{2\}-\{2\}$'); do zip -r MatchedFiles.zip $FNAME rm -fr $FNAME done ... (4 Replies)
Discussion started by: james423
4 Replies

5. Solaris

Look for distinct files under a directory matching a pattern

Hi, I'm searching for a pattern 'java' under a directory but it is returning all the files containing 'java', but I want to have only distinct files not all. please help (2 Replies)
Discussion started by: b.paramanatti
2 Replies

6. UNIX for Dummies Questions & Answers

find files NOT matching name pattern

Hi, I have following files in my directory: /TESTDONTDEL> ls -alt total 14 drwxr-xr-x 2 oracle dba 1024 May 15 06:30 . -rw-r--r-- 1 oracle dba 40 May 15 06:30 exception.txt -rw-r--r-- 1 oracle dba 19 May 15 06:22 ful_1234_test1.txt -rw-r--r-- 1... (2 Replies)
Discussion started by: sagarparadkar
2 Replies

7. UNIX for Dummies Questions & Answers

to break a file into 2 files after matching a pattern.

Hi, i need to break a file into 2 files afetr matching a pattern for ex. there is a fil, file .txt which contains here i need to look for mat $ demon if it matches then i need to transfer the data into another file till the line in which a "d6s" comes,and i have to delete tat line... (3 Replies)
Discussion started by: manit
3 Replies

8. UNIX for Dummies Questions & Answers

Find files matching a pattern

Hi, I am writing a BASH shell script. I would like to count all the files in the CURRENT directory matching a specific pattern. Could someone suggest the best/simplest way to do this. I have thought of these solutions (for simplicity the pattern is all files starting with A): ls -1 *A | wc -l... (5 Replies)
Discussion started by: msb65
5 Replies

9. UNIX for Dummies Questions & Answers

rm core files and pattern matching

Hi, I am trying to delete a load of core files, but make sure I only delete core files. The system I am using has many files with core in the name, so I obviously can not simply search for "core". I have tried using the 'find' command with pattern matching via , and know that his is the way... (3 Replies)
Discussion started by: littleIdiot
3 Replies

10. Linux

matching pattern and replacement

Hi I am trying to look for a view name in create view statement and then replace this view name with VW_ in grants line in my ddl file . cat dim_provider.sql | grep -i "create view" | while read f1 f2 f3 f4 f5 f6 f7 f8 f9 do new_vw=` echo "$f3" | cut -d "." -f2... (32 Replies)
Discussion started by: capri_drm
32 Replies
Login or Register to Ask a Question