Need help for filtering a file through awk script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help for filtering a file through awk script
# 1  
Old 09-26-2012
MySQL Need help for filtering a file through awk script

Hello Folks,
I am working on filtering a file having some special characters.
Let's say for an example a file contains person name and phone number based on positions. First 5 characters name and next 10 characters phone number. My task is to , if there is any special character in phone number (position 6-15), then that record should be removed from the file


Code:
Input File
 
RAMUN1237891111
SUPER9019199911
GOODS9*9&889000
YESIR234^789909

Desired output

Code:
RAMUN1237891111
SUPER9019199911

PLease help me with the awk script to accomplish this
# 2  
Old 09-26-2012
Try:
Code:
awk '/^......*[^[:digit:]]/ {next}1' input

# 3  
Old 09-26-2012
try this..

Code:
 awk '/^[a-z0-9A-Z]+$/' file

# 4  
Old 09-26-2012
Code:
grep -iE '^[a-z]{5}[0-9]{10}' file

# 5  
Old 09-27-2012
Working..But more precise

Thanks for your replies..
All the above command works. But I want to check for special characters at specific position. In the above sample input, if special character is present in first 5 position, the record should not be filtered.

Appreciate your help
# 6  
Old 09-27-2012
Hi

Code:
awk 'substr($0,6) ~ /^[a-z0-9A-Z]+$/' file

Guru.
This User Gave Thanks to guruprasadpr For This Post:
# 7  
Old 09-27-2012
I think you'll find that the script I provided allows the 1st five characters to be any value (except the null byte and the newline character) and will discard any line if anything other than decimal digits follow that (no matter how many more characters are on the line).

The script provided by elixir_sinari requires the 1st five characters to be uppercase or lowercase letters, the next 10 characters to be decimal digits (anything after those 1st fifteen characters will be accepted and printed).

The script provided by pamu accept and print any line that contains one or more alphanumeric characters as long as no other characters are present on the line.

If you really want to allow any character in the 1st five positions and exactly 10 decimal digits after that, a combination of the above suggestions:
Code:
grep -E '^.{5}[0-9]{10}$' file

should work.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

File filtering using awk or sed

Hello Members, I have a file, having below contents: <KEYVALUE>$4,0,1,4,966505098999--&gt;RemoteSPC: 13 SSN: 146</KEYVALUE> <KEYVALUE>$4,123,1,4,966505050198--&gt;RemoteSPC: 1002 SSN: 222,Sec:RemoteSPC: 1004 SSN: 222</KEYVALUE> <KEYVALUE>$4,123,1,4,966505050598--&gt;RemoteSPC: 1002 SSN:... (9 Replies)
Discussion started by: umarsatti
9 Replies

2. Shell Programming and Scripting

Variable filtering in awk

Hello all, can you explain why this filter does not work, it prints all the lines in the file: awk -v sel="TestString" 'sel' file while these work: awk '/TestString/' file awk -v sel="TestString" '$0~sel' file Thanks!:) (6 Replies)
Discussion started by: gio001
6 Replies

3. Shell Programming and Scripting

awk using sub , filtering textfile

i have text file as below CMF_COMP_ELEM_ GSM2_B71.WORLD_20121114130908.log 107496444 rows inserted into ALL_S1_CMF_COMP_ELEM. CMF_COMP_ELEM_ GSM3_B71.WORLD_20121114130908.log 110729006 rows inserted into ALL_S1_CMF_COMP_ELEM. CMF_COMP_ELEM_ GSM4_B71.WORLD_20121114130908.log 92549475... (8 Replies)
Discussion started by: only4satish
8 Replies

4. Shell Programming and Scripting

awk data filtering

I am trying to filter out some data with awk. If someone could help me that would be great. Below is my input file. Date: 10-JUN-12 12:00:00 B 0: 00 00 00 00 10 00 16 28 B 120: 00 00 00 39 53 32 86 29 Date: 10-JUN-12 12:00:10 B 0: 00 00 00 00 10 01 11 22 B 120: 00 00 00 29 23 32 16 29... (5 Replies)
Discussion started by: thibodc
5 Replies

5. Shell Programming and Scripting

filtering a numeric value which has '%' using awk

Hello Gurus, I have a requirement where I have to filter a value from some field which has 99% or greater than '99%'.. For ex: The Date (file -- sample.csv) will be like below Field1,Field2,Field3,Field4 860440512,844284992,16155520,99% 860440512,844284992,16155520,94%... (4 Replies)
Discussion started by: raghu.iv85
4 Replies

6. Shell Programming and Scripting

filtering with awk

i have question about awk ex: input.txt 1252468812,yahoo,3.5 1252468812,hotmail,2.4 1252468819,yahoo,1.2 msn,1252468812,8.9 1252468923,gmail,12 live,1252468812,3.4 yahoo,1252468812,9.0 1252468929,msn,1.2 output.txt 1252468812,yahoo,3.5 1252468812,hotmail,2.4 msn,1252468812,8.9... (3 Replies)
Discussion started by: zvtral
3 Replies

7. Shell Programming and Scripting

Filtering out text with awk

(0 Replies)
Discussion started by: nilekyle
0 Replies

8. Shell Programming and Scripting

awk filtering, then execution

Hi, I need to do the following but I don't know exactly what to do. I need to monitor a file ... with tail -f for example, but I know that I could do it with awk, wait for a specific string ... , then perform an action, call a script, etc. Let's say that my file name is test.txt , I need... (3 Replies)
Discussion started by: ocramas
3 Replies

9. UNIX for Dummies Questions & Answers

filtering and copying contains of a file using awk/sed

Hello folks, I have 2 files one( file1) contains the ddl for a view and file 2 contains the view defination/alias columns. I want to merge the 2 into a third file using awk/sed as follows: cheers ! :b: FILE1 ----- PROMPT FIRST_VIEW CREATE OR REPLACE FORCE VIEW FIRST_VIEW AS SELECT... (2 Replies)
Discussion started by: jville
2 Replies

10. UNIX for Advanced & Expert Users

awk filtering ?

I have a Ques. Regarding awk I have few strings in a file, like.. ABC DEF_ABC GHI_ABC GHI Now I want string which has only 'ABC', not the part of any other string as it is also present in 'DEF_ABC' Output should be ABC Please guide me asap !! Thanks :b: (4 Replies)
Discussion started by: varungupta
4 Replies
Login or Register to Ask a Question