Grep the 5th and 6th position character of a word in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep the 5th and 6th position character of a word in a file
# 1  
Old 04-08-2013
Grep the 5th and 6th position character of a word in a file

I am trying to find/grep the 5th and 6th position character (TX) of a word in a file. I tried to do
grep "....TX" file
The output gives me everything in the file with TX in it. I only need the output with the TX in the 5th and 6th position of the word. Any idea

Example:

t
Code:
est1 car CARYTXKJH 4632 car
test2 truck TRUCKKTXH 736 truck
dir655 van VANTTXMPO 23 van
test4 mini BNTVTXGFA 23 mini
bar123 bus BARUHUHFD
file2 plane FTSMAMGYU 23 plane

output file
Code:
test1 car CARYTXKJH 4632 car
dir655 van SPDLTXMPO 23 van
test4 mini BNTVTXGFA 23 mini

---------- Post updated at 01:00 PM ---------- Previous update was at 12:56 PM ----------

The output file should be:

Code:
test1 car CARYTXKJH 4632 car
dir655 van VANTTXMPO 23 van
test4 mini BNTVTXGFA 23 mini


Last edited by joeyg; 04-08-2013 at 03:02 PM.. Reason: Please wrap data and commands in CodeTags
# 2  
Old 04-08-2013
Does this give you a hint?

Code:
$ echo test1 car ABCDSXEF | awk '{if (substr($3,5,2)=="TX") print}'

$ echo test1 car ABCDTXEF | awk '{if (substr($3,5,2)=="TX") print}'
test1 car ABCDTXEF

# 3  
Old 04-08-2013
try
Code:
egrep ' [A-Z][A-Z][A-Z][A-Z]TX[A-Z]* ' <file_name>


Last edited by stuckinboredom; 04-08-2013 at 05:08 PM..
# 4  
Old 04-08-2013
grep "....TX" file
# 5  
Old 04-08-2013
If its within a word, adding a space to your grep statement should do right?
Code:
# grep " ....TX" input_file
est1 car CARYTXKJH 4632 car
dir655 van VANTTXMPO 23 van
test4 mini BNTVTXGFA 23 mini

--ahamed
# 6  
Old 04-08-2013
Thanks you both. It works
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Count specific character of a file in each line and delete this character in a specific position

I will appreciate if you help me here in this script in Solaris Enviroment. Scenario: i have 2 files : 1) /tmp/TRANSACTIONS_DAILY_20180730.txt: 201807300000000004 201807300000000005 201807300000000006 201807300000000007 201807300000000008 2)... (10 Replies)
Discussion started by: teokon90
10 Replies

2. Shell Programming and Scripting

Display combination of 4 field uniqe record and along with concatenate 5th and 6th field.

Table ACN|NAME|CITY|CTY|NO1|NO2 115|AKKK|ASH|IND|10|15 115|AKKK|ASH|IND|20|20 115|AKKK|ASH|IND|30|35 115|AKKK|ASH|IND|30|35 112|ABC|FL|USA|15|15 112|ABC|FL|USA|25|20 112|ABC|FL|USA|25|45 i have written shell script using cut command and awk programming getting error correct it and add... (5 Replies)
Discussion started by: udhal
5 Replies

3. Shell Programming and Scripting

Position of character in word

How can I represent the position of 1 (considering only the 1s after the colon) in the word from field5 and above; counting from right to left. Input: TT-124 06-03-14 08-02-10 FAS CAT1:10 TT-125-1 05-03-14 10-06-08 CAS CAT2:1010 FAT1:10000 TT-125-3 07-03-14 11-02-06 FAS FAT1:1101... (6 Replies)
Discussion started by: aydj
6 Replies

4. UNIX for Dummies Questions & Answers

Using grep to check for character at fixed position

i have a file (test.txt) that contains: 20799510617900000928000000005403020110315V 20799510617900000928000000005403020110316 20799510617900000928000000005403020110317 20799510617900000928000000005403020110318V grep V test.txt > /tmp/void.log if then mail -s "void" < test.txt fi... (2 Replies)
Discussion started by: tjmannonline
2 Replies

5. Shell Programming and Scripting

Remove 5th & 6th <td> from file

I have a page with a 6<td> structure. I need to strip the 5th and 6th <td></td> from the structure. The data in the 4th <td> varies, I can't get a pattern on it. So, I tried setting up a count of the td occurrence and then remove the 5th and 6th, but I'm not making any progress. Is there an easy,... (6 Replies)
Discussion started by: dba_frog
6 Replies

6. Shell Programming and Scripting

Remove 5th & 6th <td> from file

I have a page with a 6<td> structure. I need to strip the 5th and 6th <td></td> from the structure. The data in the 4th <td> varies, so I can't get a pattern on it. So, I tried setting up a count of the td occurrence and then remove the 5th and 6th, but I'm not making an progress. Is there an... (0 Replies)
Discussion started by: dba_frog
0 Replies

7. UNIX for Advanced & Expert Users

if 4th and 5th character of sting -ge 45 then add 1 to 3rd character

I want to know how to, given a string like W87151WR71C, if the 4th and 5th character (in this case 15) are greater than 45, then to add 1 to the 3rd character (in this case 7) and assign the revised string the variable name MODSTRING. Thanks in advance. This is ultimately to grab info from... (6 Replies)
Discussion started by: glev2005
6 Replies

8. Shell Programming and Scripting

How to check a word position in a file ?

Hello everybody, I have a file like this : "window 1 truck 3 duck 2... fire 1... etc..." and I would like to print the following number of a word I am searching for. (For example here, if I search for the word "fire", I will print "1") Thank you for your help ! (7 Replies)
Discussion started by: tibo
7 Replies

9. Shell Programming and Scripting

Change Position of word character

Hi, I have following format in file aaa with content below, and would like to seek help from forumer about how to change and swap the position on 2nd field. 5874957|901125| 95874960|650614| 95874966|870308| 901125 to be changed as 25-11-1990 for eg Can someone help please ?? :) ... (6 Replies)
Discussion started by: cedrichiu
6 Replies

10. UNIX for Dummies Questions & Answers

Grep for X character on a word

How can I grep for a certain letter that only shows on the 3rd letter or character. ex: ASGHDY SHTYRD SDTYRD IGIKGD I only want the TY part of the 3rd character so output would only be SHTYRD and DDTYRD - I only want the TY on the 3rd character. THANKS (5 Replies)
Discussion started by: jjoves
5 Replies
Login or Register to Ask a Question