Sponsored Content
Top Forums Shell Programming and Scripting Grep/Awk on 1st 2 Letters in 2nd Column of File Post 302727471 by TheNovice on Tuesday 6th of November 2012 09:34:42 AM
Old 11-06-2012
Grep/Awk on 1st 2 Letters in 2nd Column of File

Hi everyone. I need to change a script (ksh) so that it will grep on the 1st 2 letters in the second column of a 5 column file such as this one:

Code:
192.168.1.1   CAXY0_123   10ABFL000001   #   Comment
192.168.1.2   CAYZ0_123   10ABTX000002  #   Comment
192.168.2.1   FLXY0_123   11ABCA000001   #   Comment
192.168.2.2   FLYZ0_123   11ABTX000002   #   Comment
192.168.3.1   TXXY0_123   12ABCA000001  #   Comment
192.168.3.2   TXYZ0_123   12ABFL000002   #   Comment

...and print the entire line in which the match was found.

For example, I need to grep/awk for 'CA' in the CAXY0_123 and CAYZ0_123 entries in the first 2 lines of the file so that the resulting output will be:
Code:
192.168.1.1   CAXY0_123   10ABFL000001   #   Comment
192.168.1.2   CAYZ0_123   10ABTX000002  #   Comment

Can someone let me know how this can be done? I've been googling myself crazy and checking previous forum posts here but have found nothing that applies to this exact situation. I also haven't had any luck playing around with the grep/awk/nawk commands with which I'm already familiar.

Thanks!

Last edited by radoulov; 11-06-2012 at 11:07 AM..
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk+Grep Input file needs to match a column and print the entire line

I'm having problems since few days ago, and i'm not able to make it works with a simple awk+grep script (or other way to do this). For example, i have a input file1.txt: cat inputfile1.txt 218299910417 1172051195 1172070231 1172073514 1183135117 1183135118 1183135119 1281440202 ... (3 Replies)
Discussion started by: poliver
3 Replies

2. Shell Programming and Scripting

grep data on 2nd line and 3rd column

How do I grep/check the on-hand value on the second line of show_prod script below? In this case it's a "3". So if it's > 0, then run_this, otherwise, quit. > ./show_prod Product Status Onhand Price shoe OK 3 1.1 (6 Replies)
Discussion started by: joker_789us
6 Replies

3. UNIX for Dummies Questions & Answers

Grep /Awk letters X - X in every line and print it as a mac address

hey i m kinda new to this so i will appreciate any help , i have this list of values: pwwn = 0x50012482009cd7a7 nwwn=0x50012482009cd7a6 port_id = 0x280200 pwwn = 0x5001248201bcd7a7 nwwn=0x5001248201bcd7a6 port_id = 0x280300 pwwn = 0x50012482009c51ad nwwn=0x50012482009c51ac port_id =... (4 Replies)
Discussion started by: boaz733
4 Replies

4. UNIX for Dummies Questions & Answers

Grep.Need help with finding the words which start at [A-K] letters in thesecond column of the table

Hi buddies ! I need some help with one grep command :) I have this table: 1 Petras Pavardenis 1980 5 08 Linas Bajoriunas 1970 10 3 Saulius Matikaitis 1982 2 5 Mindaugas Stulgis 1990... (1 Reply)
Discussion started by: vaidastf
1 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

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

7. UNIX for Dummies Questions & Answers

Grep -v value in 2nd column

Trying to do a grep -v on a value in the 2nd column of text. So if the word apple appears in a line in the 2nd column, it would not show up when the file was cat. Seems like a simple enough operation but I just can't figure it out. Any help would be appreciated. Thanks in advance. Are apples... (4 Replies)
Discussion started by: jimmyf
4 Replies

8. 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

9. UNIX for Beginners Questions & Answers

Compare 1st column from 2 file and if match print line from 1st file and append column 7 from 2nd

hi I have 2 file with more than 10 columns for both 1st file apple,0,0,0...... orange,1,2,3..... mango,2,4,5..... 2nd file apple,2,3,4,5,6,7... orange,2,3,4,5,6,8... watermerlon,2,3,4,5,6,abc... mango,5,6,7,4,6,def.... (1 Reply)
Discussion started by: tententen
1 Replies
dechanzi(5)							File Formats Manual						       dechanzi(5)

NAME
dechanzi - A character encoding system (codeset) for Simplified Chinese DESCRIPTION
The DEC Hanzi (dechanzi) codeset consists of the following character sets: ASCII GB2312-80 Extended GB DEC Hanzi uses a 2-byte data representation for symbols and ideographic characters that are defined in GB2312-80. ASCII Characters All ASCII characters are represented in the form of single-byte, 7-bit data in the DEC Hanzi codeset; that is, the most significant bit (MSB) of the byte that represents an ASCII character is always set off. For more information on ASCII characters, refer to ascii(5). GB2312-80 Characters The code table for GB2312-80 characters is divided into 94 rows(Qu), numbered from 1 to 94. Each row has 94 columns(Wei), also numbered from 1 to 94. The code table defines a total of 7445 characters, of which 6763 are Chinese characters. Chinese characters are grouped as follows: Graphic symbols There are 682 graphic symbols, which occupy rows 1 to 9 in the code table. Frequently used (Level 1) characters There are 3755 frequently used characters, which occupy rows 16 to 55 in the code table. Less frequently used (Level 2) characters There are 3008 less frequently used characters, which occupy rows 56-87 in the code table. To differentiate GB2312-80 character codes from ASCII and Extended GB character codes, the most significant bit (MSB) of both the first byte and the second byte are set on. The following formulas show how to calculate the value for a GB2312-80 character from its row and col- umn numbers: 1st byte = A0 + Row number 2nd byte = A0 + Column number For example, if a GB2312-80 character is in the first column of the 16th row, the character's value is B0A1, which is calculated as fol- lows: 1st byte = A0(hex) + 16 = B0(hex) 2nd byte = A0(hex) + 01 = A1(hex) Extended GB Characters The Extended GB code table is similar to the GB2312 code table and is divided into 94 rows and 94 columns (8894 code points). However, the Extended GB code table provides code points for user-defined characters (UDC). The 8836 code points in this table are divided into two areas: User-defined area This area spans rows 1 to 87 and provides 8178 code points. User-defined (reserved) area This area spans rows 88 to 94 and provides 658 code points. This area is where users can define special and long-lasting user- defined characters. To differentiate Extended GB codes from ASCII codes and GB2312-80 codes, the most significant bit (MSB) of the first byte is set on while that of the second byte is set off. The following formulas show how the code value of an Extended GB character is calculated from its row and column numbers: 1st byte = A0 + Row number 2nd byte = 20 + Column number For example, if a character is positioned at the first column of the 16th row on the GB2312-80 code plane, the character's value is B021, which is calculated as follows: 1st byte = A0(hex) + 16 = B0(hex) 2nd byte = 20(hex) + 01 = 21(hex) Codeset Conversion The following codeset converter pairs are available for converting Simplified Chinese characters between dechanzi and other encoding for- mats. Refer to iconv_intro(5) for an introduction to codeset conversion. For more information about the other codeset for which dechanzi is the input or output, see the reference page specified in the list item. big5_dechanzi, dechanzi_big5 Converting from and to the Big-5 codeset: big5(5) dechanyu_dechanzi, dechanzi_dechanyu Converting from and to the DEC Hanyu codeset: dechanyu(5) eucTW_dechanzi, dechanzi_eucTW Converting from and to Taiwanese Extended UNIX Code: eucTW(5) UCS-2_dechanzi, dechanzi_UCS-2 Converting from and to UCS-2 format: Unicode(5) UCS-4_dechanzi, dechanzi_UCS-4 Converting from and to UCS-4 format: Unicode(5) UTF-8_dechanzi, dechanzi_UTF-8 Converting from and to UTF-8 format: Unicode(5) DEC Hanzi encoding is identical to the Microsoft code-page format (cp936) used for Simplified Chinese characters on PC systems. However, DEC Hanzi supports fewer characters than supported by the code page. Therefore, using converters with dechanzi in the converter name to convert between cp936 and other formats can result in some data loss. Refer to code_page(5) for more information about PC code pages. DEC Hanzi Fonts The operating system provides both screen and printer fonts for DEC Hanzi characters. The following bitmap fonts are grouped according to family and reflect various sizes and typefaces for 75dpi and 100dpi display devices: Fangsongti Family: -adecw-fangsongti-medium-r-normal--24-240-75-75-m-240-gb2312.1980-1 -adecw-fangsongti-medium-r-normal--34-340-75-75-m-340-gb2312.1980-1 -adecw-fangsongti-medium-r-normal--24-240-100-100-m-240-gb2312.1980-1 -adecw-fangsongti-medium-r-normal--34-340-100-100-m-340-gb2312.1980-1 Heiti Family: -adecw-heiti-medium-r-normal--16-160-75-75-m-160-gb2312.1980-1 -adecw-heiti-medium-r-normal--24-240-75-75-m-240-gb2312.1980-1 -adecw-heiti- medium-r-normal--34-340-75-75-m-340-gb2312.1980-1 -adecw-heiti-medium-r-normal--16-160-100-100-m-160-gb2312.1980-1 -adecw-heiti-medium-r- normal--24-240-100-100-m-240-gb2312.1980-1 -adecw-heiti-medium-r-normal--34-340-100-100-m-340-gb2312.1980-1 Kaiti Family: -adecw-kaiti-medium-r-normal--24-240-75-75-m-240-gb2312.1980-1 -adecw-kaiti-medium-r-normal--34-340-75-75-m-340-gb2312.1980-1 -adecw-kaiti- medium-r-normal--24-240-100-100-m-240-gb2312.1980-1 -adecw-kaiti-medium-r-normal--34-340-100-100-m-340-gb2312.1980-1 Screen Family: -adecw-screen-medium-r-normal--18-180-75-75-m-160-gb2312.1980-1 -adecw-screen-medium-r-normal--24-240-75-75-m-240-gb2312.1980-1 -adecw- screen-medium-r-normal--18-180-100-100-m-160-gb2312.1980-1 -adecw-screen-medium-r-normal--24-240-100-100-m-240-gb2312.1980-1 -adecw-screen- medium-r-normal--18-180-100-100-m-160-gb2312.1980-UDC -adecw-screen-medium-r-normal--24-240-100-100-m-240-gb2312.1980-UDC Songti Family: -adecw-songti-medium-r-normal--16-160-75-75-m-160-gb2312.1980-1 -adecw-songti-medium-r-normal--24-240-75-75-m-240-gb2312.1980-1 -adecw- songti-medium-r-normal--34-340-75-75-m-340-gb2312.1980-1 -adecw-songti-medium-r-normal--16-160-100-100-m-160-gb2312.1980-1 -adecw-songti- medium-r-normal--24-240-100-100-m-240-gb2312.1980-1 -adecw-songti-medium-r-normal--34-340-100-100-m-340-gb2312.1980-1 The operating system provides the following PostScript printer fonts for DEC Hanzi characters: Hei-GB2312-80 XiSong-GB2312-80 For general information on printing Asian language text, refer to i18n_printing(5). SEE ALSO
Commands: locale(1) Others: ascii(5), big5(5), Chinese(5), code_page(5), dechanyu(5), eucTW(5), GBK(5), i18n_intro(5), i18n_printing(5), iconv_intro(5), l10n_intro(5), sbig5(5), telecode(5), Unicode(5) dechanzi(5)
All times are GMT -4. The time now is 07:17 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy