wildcard in regex for awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting wildcard in regex for awk
# 1  
Old 09-21-2012
wildcard in regex for awk

Hello I have a file like :

Code:
20120918000001413 | 1.17.163.89 | iSelfcare | MSISDN | N 
20120918000001806 | 1.33.27.100 | iSelfcare | 5564 | N
....

I want to extract all lines that have on 4th field (considering "|" the separator ) something other than just digits. I want to do this using a awk one-liner ( I don;t want shell commands because combination of grep, while, cut.. etc takes way too much time)

I have this command :

Code:
awk -F'|' '$4 == " [A-Z]* "' target_file.txt

But it doesn't work.

Last edited by Scrutinizer; 09-21-2012 at 11:16 AM.. Reason: code tags also for data sample
# 2  
Old 09-21-2012
Try this one
Code:
awk -F\| '{if($4~/[a-zA-Z]+/){print}}' filename

This User Gave Thanks to senthilkumark For This Post:
# 3  
Old 09-21-2012
Quote:
Originally Posted by senthilkumark
Try this one
Code:
awk -F\| '{if($4~/[a-zA-Z]+/){print}}' filename

Hello , thank you, exactly what I needed!
awk rules (but I'm too lazy to learn it :P )
# 4  
Old 09-21-2012
Code:
awk -F\| '$4!~/^[0-9 ]+$/' input_file


JUST ANYTHING other than numbers....including special characters like $%^ etc
This User Gave Thanks to msabhi For This Post:
# 5  
Old 09-21-2012
Quote:
Originally Posted by msabhi
Code:
awk -F\| '$4!~/^[0-9 ]+$/' input_file

JUST ANYTHING other than numbers....including special characters like $%^ etc
Yes, this is more complete and accurate.
# 6  
Old 09-21-2012
Code:
awk -F\| '$4~/[^0-9 ]/' file

This User Gave Thanks to Scrutinizer For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Problem with use of the ? wildcard in regex substitution.

I'm trying to use Larry Wall's rename (prename) tool to rename multiple files: $ ls -1 blar.m4mp3 BLAH.mpmp3 bar foo.m4mp3 foo bar.mpmp3 I'm trying to fix the extensions so they're all .mp3: rename 's/m?mp3/mp3/' *mp3 I expect m?mp3 to match the extensions,... (3 Replies)
Discussion started by: ropers
3 Replies

2. Shell Programming and Scripting

Regex within IF statement in awk

Hello to all, I have: X="string 1-" Y="-string 2" Z="string 1-20-string 2"In the position of the number 20 could be different numbers, but I'm interest only when the number is 15, 20,45 or 70. I want to include an IF within an awk code with a regex in the following way. ... (12 Replies)
Discussion started by: Ophiuchus
12 Replies

3. Shell Programming and Scripting

awk equivalent of regex

Hi all, Can someone tell me what's the (g)awk equal of this simple regex to find ip addresses in urls: egrep "^http://{1,3}\.{1,3}\.{1,3}\.{1,3}(:{1,5})?/"Input: http://10.0.0.1/query.exe http://11y10x09w:80/howaboutme http://192.168.100.190:1234/takeme.gpg Output:... (8 Replies)
Discussion started by: r4v3n
8 Replies

4. UNIX for Dummies Questions & Answers

Using AWK and regex

Hi can you suggest in this regard The sample.txt conatins the data name lines type sam 12 txt sam 24 xls sam 36 pdf ram 32 txt ram 45 sxls ram 58 word sam 92 jpeg sam 21 gif sam 22 ltf from the data i need to sum all line... (5 Replies)
Discussion started by: krashraj
5 Replies

5. Shell Programming and Scripting

awk regex problem

hi everyone suppose my input file is ABC-12345 ABCD-12345 BCD-123456 i want to search the specific pattern which looks like - in a file so i used this command cat $file | awk ' { if ($0 ~ /-/) { print } }' so it gives me the result as ABCD-12345 BCD-12345 BCD-12345 ... (31 Replies)
Discussion started by: aishsimplesweet
31 Replies

6. Shell Programming and Scripting

AWK regex to find only numbers

Hi guys I need to find both negative and positive numbers from the following text file. And i also dont need 0. 0 8 -7 -2268 007 -07 -00 -0a0 0a0 -07a0 7a00 0a0 Can someone please give a regex to filter out the values in red. I tried a few things in awk but it didnt work... (9 Replies)
Discussion started by: sridanu
9 Replies

7. Shell Programming and Scripting

sed to awk (regex pattern) how?

Hello, I am trying to covert a for statement into a single awk script and I've got everything but one part. I also need to execute an external script when "not found", how can I do that ? for TXT in `find debugme -name "*.txt"` ;do FPATH=`echo $TXT | sed 's/\(.*\)\/\(.*\)/\1/'` how... (7 Replies)
Discussion started by: TehOne
7 Replies

8. Shell Programming and Scripting

Extracting a regex with awk

I have a regexp that I wish to match against every line of a file using awk. But I do not want to substitute it or select the line. I want to pull the matched text out and put it in a different file, line by line. What is the correct awk usage to *extract* a regexp and put it in another... (11 Replies)
Discussion started by: Enobarbus37
11 Replies

9. Shell Programming and Scripting

awk or regex

Hi! I want to made a program that will generate code like this: {{Navedi XYZ |avtor=XYZ1 |naslov=XYZ2 |leto_izzida=XYZ3 |zalozba=XYZ4 |kraj=XYZ5 |isbn=XYZ6 |cobiss_id=XYZ7 }} from input like this: <b> ODGOVORNOST............. : <a... (5 Replies)
Discussion started by: smihael
5 Replies

10. UNIX for Dummies Questions & Answers

Find wildcard .shtml files in wildcard directories and removing them- How's it done?

I'm trying to figure out how to build a small shell script that will find old .shtml files in every /tgp/ directory on the server and delete them if they are older than 10 days... The structure of the paths are like this: /home/domains/www.domain2.com/tgp/ /home/domains/www.domain3.com/tgp/... (1 Reply)
Discussion started by: Neko
1 Replies
Login or Register to Ask a Question