awk or grep to search one column and output the other


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk or grep to search one column and output the other
# 8  
Old 07-20-2013
If you insist on using this approach, a couple of points.

1. cat is not necessary:
Code:
while ...; do
  ...
done < file

2. ^$row will match anything starting with "$row". Qualify it better. i.e.:
Code:
$ cat file
A
AA
AAA
AAAA
$ row=A 
$ grep "^$row" file
A
AA
AAA
AAAA
$ grep "^$row\b" file
A

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep from FileA, search in FileB, edit FileC > Output

Hello, Similar question to my previous posts. I am sorry for the trouble... Just checked my old threads but I can not implement any solution into this case.. My aim is to grab each line in fileA, check it in fileB and merge with fileC (tab separated) in corresponding line as given below: FileA:... (2 Replies)
Discussion started by: baris35
2 Replies

2. Shell Programming and Scripting

Search for string in column using variable: awk

I'm interested to match column pattern through awk using an external variable for data: -9 1:751343:T:A -9 0 T A 0.726 -5.408837e-03 9.576603e-03 7.967536e-01 5.722312e-01 -9 1:751756:T:C -9 0 T C 0.727 -5.360458e-03 9.579447e-03 7.966977e-01 5.757858e-01... (7 Replies)
Discussion started by: genome
7 Replies

3. Shell Programming and Scripting

Search/grep on row and column wise

Hello, I have a comma seperate metadata as follows: CITY ,COUNTY,STATE,COUNTRY NEW_YORK,NYC ,NY ,USA NEWARK ,ESSEX ,NJ ,USA CHICAGO ,COOK ,IL ,USA SEATTLE ,MINER ,WA ,USA In my process, I get two key values ie CITY NAME (can be one of the... (7 Replies)
Discussion started by: calredd
7 Replies

4. Shell Programming and Scripting

awk search pattern in column

Want to search a pattern in column using the below command which not helpful awk -F"\|" '$1 == '"${VAR}"' {print $1,$2}' file how to search using "==" with variable other than the below case. awk -F"\|" '$1 ~ /'"${VAR}"'/ {print $1,$2}' file (14 Replies)
Discussion started by: Roozo
14 Replies

5. Shell Programming and Scripting

How to awk or grep the last column in file when date on column contains spaces?

Hi have a large spreadsheet which has 4 columns APM00111803814 server_2 96085 Corp IT Desktop and Apps APM00111803814 server_2 96085 Corp IT Desktop and Apps APM00111803814 server_2 96034 Storage Mgmt Team APM00111803814 server_2 96152 GWP... (6 Replies)
Discussion started by: kieranfoley
6 Replies

6. Shell Programming and Scripting

awk : search last index in specific column

I am trying to search a given text in a file and find its last occurrence index. The task is to append the searched index in the same file but in a separate column. I am able to accomplish the task partially and looking for a solution. Following is the detailed description: names_file.txt ... (17 Replies)
Discussion started by: tarun.trehan
17 Replies

7. Shell Programming and Scripting

To search a word in particular column using awk

I have a data in a file like this 1 praveen bmscollege 2 shishira bnmit 3 parthiva geethamce I want to search "praveen" using awk command i tried like this but i did not get awk `$2="praveen" {print $0} ` praveen.lst can anyone help me solving this problem in... (2 Replies)
Discussion started by: praveenhegde
2 Replies

8. Shell Programming and Scripting

AWK in column search

Hi friends , I am new to unix ,need your help to fix this there is a ~ deliminated file. how to find the 5th column of the row. awk 'print $5 ' abc.txt it doesnot work . it works for table deliminated file. My data file is like the following manner. abc.txt -------- a~b~c~d~e~f... (3 Replies)
Discussion started by: imipsita.rath
3 Replies

9. Shell Programming and Scripting

Search for a column by name in awk

Hi, I have a file that has many columns. Let us say "Employee_number" "Employee_name" "Salary". I want to display all entries in a column by giving all or part of the column name. For example if I input "name" I want all the employee names printed. Is it possible to do this in a simple manner... (2 Replies)
Discussion started by: kskkarthik
2 Replies
Login or Register to Ask a Question
Net::Trac::TicketSearch(3pm)				User Contributed Perl Documentation			      Net::Trac::TicketSearch(3pm)

NAME
Net::Trac::TicketSearch - A ticket search (custom query) in Trac SYNOPSIS
my $search = Net::Trac::TicketSearch->new( connection => $trac ); $search->query( owner => 'hiro', status => { 'not' => [qw(new reopened)] }, summary => { 'contains' => 'yatta!' }, reporter => [qw( foo@example.com bar@example.com )] ); print $_->id, " " for @{$search->results}; DESCRIPTION
This class allows you to run ticket searches on a remote Trac instance. ACCESSORS
connection limit [NUMBER] Get/set the maximum number of results to fetch. Default is 500. This may also be limited by the Trac instance itself. results Returns an arrayref of Net::Trac::Tickets for the current query. url Returns the relative URL for the current query (note the format will be CSV). METHODS
query [PARAMHASH] Performs a ticket search with the given search conditions. Specify a hash of "column =" value> pairs for which to search. Values may be a simple scalar, a hashref, or an arrayref. Specifying a hashref allows you to select a different operator for comparison (see below for a list). An arrayref allows multiple values to be or'd for the same column. Unfortunately Trac has no way of anding multiple values for the same column. Valid operators are "is" (default), "not", "contains", "lacks", "startswith", and "endswith". Returns undef on error and the results otherwise. LICENSE
Copyright 2008-2009 Best Practical Solutions. This package is licensed under the same terms as Perl 5.8.8. perl v5.12.3 2009-05-27 Net::Trac::TicketSearch(3pm)