If 2nd column is matched


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting If 2nd column is matched
# 1  
Old 03-18-2015
If 2nd column is matched

Both codes not working for me.

Code:
whois nba.com| sed -n '/Registry Registrant ID:/,/Registrant 
whois ymas.com| sed -n '/Registry Registrant ID:/,/Registrant 
whois ymas.com.pt| sed -n '/Registry Registrant ID:/,/Registrant 
whois ymas.com.pt| sed -n '/Registry Admin ID:/,/Admin Email:/p' 
whois ymas.com.pt| sed -n '/Registry Tech ID:/,/Tech Email:/p' > 
whois ymas.com.uy| sed -n '/Registry Registrant ID:/,/Registrant 
whois ymas.com.uy| sed -n '/Registry Admin ID:/,/Admin Email:/p'


Code:
cat aa.sh|awk -F. '$2 == "com|"  {print $0}'
 
cat aa.sh|awk -F. '$2 == "com"  {print $0}'

Desired output
Code:
whois nba.com| sed -n '/Registry Registrant ID:/,/Registrant 
whois ymas.com| sed -n '/Registry Registrant ID:/,/Registrant

# 2  
Old 03-18-2015
If the separator is . then the field (#2) ends at the next . or at the end of the line.
You can do an ERE-search:
Code:
awk -F. '$2 ~ /com|/ {print $0}' aa.sh

or limit the search to the beginning of the field
Code:
awk -F. '$2 ~ /^com\|/ {print $0}' aa.sh

In the latter case I have escaped \| because | is a special ERE character unless at the very beginning or the very end or within [ ].
This User Gave Thanks to MadeInGermany For This Post:
# 3  
Old 03-18-2015
cool,

this works for me
Code:
awk -F. '$2 ~ /^com\|/ {print $0}'

---------- Post updated at 10:51 AM ---------- Previous update was at 10:49 AM ----------

but there is what if,,,

waht if the "|" is not existing,

out code works only because of "|" it can fetsh easily

Last edited by Franklin52; 03-19-2015 at 08:18 AM.. Reason: Fixed code tags
# 4  
Old 03-18-2015
How about
Code:
awk '!/com\./' file
whois nba.com| sed -n '/Registry Registrant ID:/,/Registrant 
whois ymas.com| sed -n '/Registry Registrant ID:/,/Registrant

---------- Post updated at 17:41 ---------- Previous update was at 17:40 ----------

... or even better
Code:
awk '/com[^.]/' file
whois nba.com| sed -n '/Registry Registrant ID:/,/Registrant 
whois ymas.com| sed -n '/Registry Registrant ID:/,/Registrant

This User Gave Thanks to RudiC For This Post:
# 5  
Old 03-18-2015
this is not working on general

Code:
awk '!/com\./'

this is the right answer of all,
Code:
awk '/com[^.]/'


Last edited by Franklin52; 03-19-2015 at 08:18 AM.. Reason: adding code tags
# 6  
Old 03-18-2015
Still a
Code:
awk '/[.]com\|/'

or
Code:
awk '$2 ~ /[.]com\|/'

is more precise, just like the previous one with dot-separated fields.
--
A correction: the | should be escaped \| even at the beginning or end.
Otherwise certain awk versions match everything, and other awk versions give an ERE error.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Linux

Print the 1st column and the value in 2nd or 3rd column if that is different from the values in 1st

I have file that looks like this, DIP-17571N|refseq:NP_651151 DIP-17460N|refseq:NP_511165|uniprotkb:P45890 DIP-17571N|refseq:NP_651151 DIP-19241N|refseq:NP_524261 DIP-19241N|refseq:NP_524261 DIP-17151N|refseq:NP_524316|uniprotkb:O16797 DIP-19588N|refseq:NP_731165 ... (2 Replies)
Discussion started by: Syeda Sumayya
2 Replies

2. UNIX for Dummies Questions & Answers

How to merge two tables based on a matched column?

Hi, Please excuse me , i have searched unix forum, i am unable to find what i expect , my query is , i have 2 files of same structure and having 1 similar field/column , i need to merge 2 tables/files based on the one matched field/column (that is field 1), file 1:... (5 Replies)
Discussion started by: karthikram
5 Replies

3. Shell Programming and Scripting

Find matched patterns in a column of 2 files with different size and merge them

Hi, i have input files like below:- input1 Name Seq_ID NewID Scores MT1 A0QZX3 1.65 277.4 IVO A0QZX3 1.65 244.5 HPO A0QZX3 1.65 240.5 RgP A0Q3PP 5.32 241.0 GX1 LPSZ3S 96.1 216.9 MEL LPSS3X 4.23 204.1 LDD LPSS3X 4.23 100.2 input2 Fac AddName NewID ... (9 Replies)
Discussion started by: redse171
9 Replies

4. Shell Programming and Scripting

Transpose from 2nd column till the last column

Hi I have 5 columns like this a b c d e f g h i j k l m n o From 2nd column till the 5th column of every record, I would like to transpose them as rows, so my output file contains only one row a b c d e f g h i j (9 Replies)
Discussion started by: jacobs.smith
9 Replies

5. Shell Programming and Scripting

Calculate 2nd Column Based on 1st Column

Dear All, I have input file like this. input.txt CE2_12-15 3950.00 589221.0 9849709.0 768.0 CE2_12_2012 CE2_12-15 3949.00 589199.0 9849721.0 768.0 CE2_12_2012 CE2_12-15 3948.00 589178.0 9849734.0 768.0 CE2_12_2012 CE2_12-52 1157.00 ... (3 Replies)
Discussion started by: attila
3 Replies

6. Shell Programming and Scripting

1st column,2nd column on first line 3rd,4th on second line ect...

I need to take one column of data and put it into the following format: 1st line,2nd line 3rd line,4th line 5th line,6th line ... Thanks! (6 Replies)
Discussion started by: batcho
6 Replies

7. Shell Programming and Scripting

comparing column of two different files and print the column from in order of 2nd file

Hi friends, My file is like: Second file is : I need to print the rows present in file one, but in order present in second file....I used while read gh;do awk ' $1=="' $gh'" {print >> FILENAME"output"} ' cat listoffirstfile done < secondfile but the output I am... (14 Replies)
Discussion started by: CAch
14 Replies

8. Shell Programming and Scripting

Replace data of one column with data on other file corresponding to transaction ID matched

Hi All, I have two files one of which having some mobile numbers and corresponding value whose sample content as follows: 9058629605,8.0 9122828964,30.0 And in second file complete details of all mobile numbers and sample content as follows and delimeter used is comma(,): ... (8 Replies)
Discussion started by: poweroflinux
8 Replies

9. Shell Programming and Scripting

Parse 1 column and add 2nd column

I'm racking my brain on this one! :( I have a list like this: Paul 20 Paul 25 Paul 30 Frank 10 Julie 15 Julie 13 etc, etc... I've been trying to figure out a way to have the output display the name in the first column ONCE and add the numbers in the second column and display that... (2 Replies)
Discussion started by: sdlennon
2 Replies

10. Shell Programming and Scripting

Column matched in two files

I have two files with multiple columns separated by commas. I want to search one column from the first file in the second file; If there is a matching, will append that matched row to the first file. Let me show an example... (unique values in the search column) First file aa,reg1,bb,cc,dd,ff... (6 Replies)
Discussion started by: lalelle
6 Replies
Login or Register to Ask a Question