awk - checking last three characters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk - checking last three characters
# 1  
Old 06-27-2013
Hammer & Screwdriver awk - checking last three characters

Hello, I am working with some very large files (upwards of 1M records). I have written code to parse out a lot of the data and am using awk rather than a built-in "while read LINE" for performance (I have tested both ways). That said, I now need to read each of these incoming lines, check the ninth field, then check to see if the last three characters of that field match a certain string constant. Anyone have ideas on this? Sample record below:

Code:
field1:field2:field3:field4:field5:field6:field7:field8:mycheckfieldSTC:field10.....
field1:field....:field9:field10.....

Not actual data, but at least you get the idea. There are a fixed number of fields but did not think that relevant as the only field I want to check is nine.

Thanks in advance!
# 2  
Old 06-27-2013
Code:
awk -F: '$9 ~ /STC$/' file

This User Gave Thanks to RudiC For This Post:
# 3  
Old 06-27-2013
Thanks! That worked perfectly. I had to do some other checks around it, but that was the one piece I couldn't figure out.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Checking the user input in perl for characters and length

My question is basically as the title says. How can I check a user inputted string is only certain characters long (for example, 3 characters long) and how do I check a user inputted string only contains certain characters (for example, it should only contain the characters 'u', 'a', 'g', and 'c')... (4 Replies)
Discussion started by: Eric1
4 Replies

2. Shell Programming and Scripting

Checking a pattern in file and the count of characters

I am having a zipped file which has the following URL contents - 98.70.217.222 - - "GET /liveupdate-aka.symantec.com/1340071490jtun_nav2k8enn09m25.m25?h=abcdefgh HTTP/1.1" 200 159229484 "-" "hBU1OhDsPXknMepDBJNScBj4BQcmUz5TwAAAAA" "-" In this line here is we only need to consider the... (4 Replies)
Discussion started by: Naks_Sh10
4 Replies

3. Shell Programming and Scripting

Help with checking that 2 variables contain matching characters

hi i am writing a hangman script and am having trouble checking the correct letters against the word i need the script to compare the word against the letters guessed that are correct so once all the letters within the word have been guessed it will alow me to create a wining senario eg ... (3 Replies)
Discussion started by: lsecer
3 Replies

4. Shell Programming and Scripting

Checking conditions with AWK

Input File1 0BB2 2A11 Split,FriApr80625,1507_7RAID5 0BF6 2829 Synchronized,FriJan140653,1507_7RAID5 0BF6 282A Split,FriApr80625,1507_7RAID5 0C7C 199E Synchronized,FriJan140653,1507_7RAID5 0C7C 1BCC Split,FriApr80625,1507_7RAID5 0DCA 0A9B ... (12 Replies)
Discussion started by: greycells
12 Replies

5. Shell Programming and Scripting

Checking a file using awk

I have a file that looks like this, with the first number in each block within each SOURCE declaration being a distance. %( PHASES P %) %( SOURCES (10,0.0) (13,0.0) (16,0.0) (19,0.0) (22,0.0) (25,0.0) (28,0.0) (31,0.0) (34,0.0) (37,0.0) (0 Replies)
Discussion started by: kristinu
0 Replies

6. Shell Programming and Scripting

awk if percent % checking

hi everyone, # cat a a 10% b 25.5% c 91% d 50% # cat a | awk '$2 >= 90%; END {print $_}' awk: $2 > 90%; END {print $_} awk: ^ syntax error awk: each rule must have a pattern or an action part how to do only print when 2nd coln >= 90%. Thanks (6 Replies)
Discussion started by: jimmy_y
6 Replies

7. Shell Programming and Scripting

Checking the length using awk??

I have following data in a file a.txt HELLO123456789 HELLO098765432 HELLO322366565 HELLO2343435 HELLO45343 I have to filter those lines whose length is not equal to 14 using awk. Thanks in advance:b: (1 Reply)
Discussion started by: nohup
1 Replies

8. UNIX for Advanced & Expert Users

Checking for certain characters

Could anyone help with the following enquiry.. i have a file in the following format: ID .... VALUE A001 .... 100 B002 .... 200 A004 .... 300 B006 .... 100 A997 .... 200 B776 .... ... (13 Replies)
Discussion started by: SAMZ
13 Replies

9. UNIX for Dummies Questions & Answers

Ksh Checking if string has 2 characters and does not contain digits?

How could I check if a string variable contains at least (or only) 2 characters, and check and make sure that the string does not contain any numeric digits?...I need to know how to do this as simple as possible. and I am using the Ksh shell. Thanks. (1 Reply)
Discussion started by: developncode
1 Replies

10. Shell Programming and Scripting

Awk type checking

Hello, How to check if two variables( fields in awk) have the same datatype ( INTEGER , REAL, TEXT ) ? (2 Replies)
Discussion started by: scotty_123
2 Replies
Login or Register to Ask a Question