Search parameters on file with AWK


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search parameters on file with AWK
# 1  
Old 12-14-2010
Search parameters on file with AWK

Hello everyone!!

I need help with this please:

I have a file with this content:

Code:
56977964333        730030201857822     1
                                       2
                                       4
56976969284        730030201412442     1
                                       2
56990513943        730030201862571     1
                                       2
                                       4
56977981017        730030108483501     1
                                       2
                                       4
56976986997        730030108745757     1
                                       2

and I need ouput all first parameters that have "4". For example

Code:
56977964333      
56990513943   
56977981017

I hope you can help me please!!
Thanks for all and sorry for my English Smilie
# 2  
Old 12-14-2010
Code:
awk '$1~/4/' file

# 3  
Old 12-14-2010
Or:
Code:
 awk 'NF==3{a=$1}$NF==4{print a}' file

# 4  
Old 12-14-2010
Thank you so much bartus11 and Klashxx for the help.
Was much more simple than I thought.

Thanks again!

Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk search patterns from file in another

I would like to grep for aaa and bbb and ccc from one line in file1.txt in any order on a line on file2.txt file1.txt aaa bbb ccc ddd fff ggg hhh ddd jjj jjj cccfile2.txt aaa bbb ccc ddd fff ggg --> output whole line since it matches with aaa bbb ccc of file1.txt aaa ddd jjj hhh --> no... (1 Reply)
Discussion started by: sdf
1 Replies

2. Shell Programming and Scripting

Search and replace from file in awk using a 16 bit text file

Hello, Some time ago a helpful awk file was provided on the forum which I give below: NR==FNR{A=$0;next}{for(j in A){split(A,P,"=");for(i=1;i<=NF;i++){if($i==P){$i=P}}}}1 While it works beautifully on English and Latin characters i.e. within the ASCII range of 127, the moment a character beyond... (6 Replies)
Discussion started by: gimley
6 Replies

3. Shell Programming and Scripting

awk get search pattern from a file.

Here Is a problem I am facing with awk. Query --> I want to search for a string in a file and print next 15 lines below the matched string. 1.We do not have GNU grep so cannot use grep -A or grep -B commands. 2. Instead of passing the search pattern as a string to awk. I want the awk to... (4 Replies)
Discussion started by: togotutor
4 Replies

4. Shell Programming and Scripting

How to use Bash and awk to search in a file?

I have the following code as a file which a user can choose with an option to search in that file. The file name is not specified and can have any name and extension. Now a sample of this file is like this: 1,root,init,20,0.0,0.1,0:01.78 1008,root,migration/0,1,2.0,1.8,7:04.32... (4 Replies)
Discussion started by: bashily
4 Replies

5. Shell Programming and Scripting

Using Awk to Search to a Certain point in File

a command like the one below will search a file from the date and time specified to the END of the log. awk "/^2011-12-26 14:37/,0" /apps/prodction.log How do i make it so that it doesn't search to the END of the log but instead stops at a specified section of the log. for instance, if i... (1 Reply)
Discussion started by: SkySmart
1 Replies

6. Shell Programming and Scripting

search and edit in the same file using awk

Hi, I am having a user.txt contains the name of users and passwd.txt file contains as passwd.txt $cat usr.txt root bin daemon cap $cat passwd.txt root:x:0:0:root:/root:/usr/bin/ksh bin:x:1:1:bin:/bin:/sbin/csh daemon:x:2:2:daemon:/sbin:/usr/bin/ksh adm:x:3:4:adm:/var/adm:/sbin/nologin... (4 Replies)
Discussion started by: Manabhanjan
4 Replies

7. Shell Programming and Scripting

Using awk to when reading a file to search and output to file

Hi, I am not sure if this will work or not. I am getting a syntax error. I am reading fileA, using an acct number field trying to see if it exists in fileB and output to new file. Can anyone tell me if what I am doing will work or should I attempt it another way? Thanks. exec < "${fileA}... (4 Replies)
Discussion started by: ski
4 Replies

8. Shell Programming and Scripting

Read a file and search a value in another file create third file using AWK

Hi, I have two files with the format shown below. I need to read first field(value before comma) from file 1 and search for a record in file 2 that has the same value in the field "KEY=" and write the complete record of file 2 with corresponding field 2 of the first file in to result file. ... (11 Replies)
Discussion started by: King Kalyan
11 Replies

9. Shell Programming and Scripting

How to pass parameters to an awk file?

I have an awk file where I need to pass a filename and a value as a parameter from a sh script. I need to know how to pass those values in the sh script and how to use the same in the awk file. Thanks in advance!!! Geetha (3 Replies)
Discussion started by: iamgeethuj
3 Replies

10. Shell Programming and Scripting

Awk: To search for 02/24/2005 in a file

Hi I am writing a shell script in which I have to search all records which are dated 02/24/2005. The file consists of date in mm/dd/yyy format and corresponding job name. When I tried to use awk /"$1"/ filelist where $1 is input date e.g 02/24/2005 , it gives an error . I want to... (2 Replies)
Discussion started by: dalviahmed
2 Replies
Login or Register to Ask a Question