A question about awk search


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting A question about awk search
# 1  
Old 09-18-2012
A question about awk search

I want to search a field and print first field in these record. There is a "*" in the field I want to search, like "TRBD2*01".
I used the command like this:
Code:
awk '/TRBD2*01/ {print $1}' test.txt

But it doesn't work. The command line

Code:
 awk '/TRBD2/ {print $1}' test.txt

will work.

How should i do?

Thank you!
# 2  
Old 09-18-2012
Code:
 
awk '/TRBD2[*]01/ {print $1}' test.txt

This User Gave Thanks to rdrtx1 For This Post:
# 3  
Old 09-18-2012
Awk treats * as a wildcard character - represents zero or more chars.
For a literal * you need to escape the character:

Code:
awk '/TRBD2\*01/ {print $1}' test.txt

This User Gave Thanks to Chubler_XL For This Post:
# 4  
Old 09-18-2012
perfect! Thank you!
# 5  
Old 09-18-2012
I also do this sometimes since it seems clearer to me:

Code:
awk '/TRBD2[*]01/ { print $1 }'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Grep/awk using a begin search pattern and end search pattern

I have this fileA TEST FILE ABC this file contains ABC; TEST FILE DGHT this file contains DGHT; TEST FILE 123 this file contains ABC, this file contains DEF, this file contains XYZ, this file contains KLM ; I want to have a fileZ that has only (begin search pattern for will be... (2 Replies)
Discussion started by: vbabz
2 Replies

2. Shell Programming and Scripting

awk variable search and line count between variable-search pattern

Input: |Running the Rsync|Sun Oct 16 22:48:01 BST 2016 |End of the Rsync|Sun Oct 16 22:49:54 BST 2016 |Running the Rsync|Sun Oct 16 22:54:01 BST 2016 |End of the Rsync|Sun Oct 16 22:55:45 BST 2016 |Running the Rsync|Sun Oct 16 23:00:02 BST 2016 |End of the Rsync|Sun Oct 16 23:01:44 BST 2016... (4 Replies)
Discussion started by: busyboy
4 Replies

3. Shell Programming and Scripting

Another sed/awk search=>replace question

Hello, Need a little bit of help. Basically I need to replace lines in a file which were calculated wrong as it would 12 hours to regenerate the data. I need to calculate values based on other files which I've managed to figure out with grep/cut but now am stuck on how to shove these new... (21 Replies)
Discussion started by: f77coder
21 Replies

4. Shell Programming and Scripting

Search and replace question

Hi all, I am trying to modify an xml file and I wanted to search and replace using the sed command but here is my issue. I want to search and replace maximumHeapSize="512" and replace it with maximumHeapSize="768" but I have multiple files with different values so I can't search for... (2 Replies)
Discussion started by: reyes99
2 Replies

5. Shell Programming and Scripting

Search several string and convert into a single line for each search string using awk command AIX?.

I need to search the file using strings "Request Type" , " Request Method" , "Response Type" and by using result set find the xml tags and convert into a single line?. below are the scenarios. Cat test Nov 10, 2012 5:17:53 AM INFO: Request Type Line 1.... (5 Replies)
Discussion started by: laknar
5 Replies

6. Emergency UNIX and Linux Support

search replace regex question

Hi, I need to run a search and replace on a large database, what I need to change is all instances of #### (eg. 1764 or 1964) to (####) (eg. (1764) or (1964)) But there might be other numbers in there such as (1764) and I do not need those changed to ((1764)) How can I... (7 Replies)
Discussion started by: lawstudent
7 Replies

7. UNIX for Dummies Questions & Answers

quick question vi word search

hi, while in vi, we use /string to look for the particular string. after that operation, the particular string is highlighted in yellow color. how do i take the highlight off? thanks so much. (1 Reply)
Discussion started by: hobiwhenuknowme
1 Replies

8. Shell Programming and Scripting

looping search question

This is my requirement-- I have a list file that contains a list of 50 words. eg word1 word2 word3 I want to search/grep for each of those words in a directory/and subdirectories and list the file in which that word exists. Ne ideas for script/command? I know grep -r <pattern>... (3 Replies)
Discussion started by: alfredo123
3 Replies

9. UNIX for Dummies Questions & Answers

search and replace one more question

Hi, I have a file that contains the following contents: 14:05 apple orange123 456mango 16:45 banana I wanted to replace ONLY the "14:05 " and "16:45" with nothing and trying to use the following syntax sed -e 's/*//g' -e 's/^: //g' my_file > new_temp cat new_temp apple orange... (2 Replies)
Discussion started by: ghazi
2 Replies

10. UNIX Desktop Questions & Answers

search question

From time to time I need to extract portions of a very large weblogic log file. Each line in the file begins with a date stamp like this: ####<Dec 26, 2005 10:58:30 PM CST> What would be the most efficient way to select all lines in the file between, say, 10:15 PM and 10:20 PM? (1 Reply)
Discussion started by: kf199
1 Replies
Login or Register to Ask a Question