[Solved] Extract First character in fourth column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] Extract First character in fourth column
# 1  
Old 02-13-2014
[Solved] Extract First character in fourth column

Hi Experts,

I am new to UNIX. One of my file records are like below

Code:
220 IN C/A 515013 NULL NULL 
220 IN C/A 515017 NULL NULL
225 IN C/A 333701 NULL NULL
225 IN C/A 515034 NULL NULL
225 IN C/A 499201 NULL NULL
225 IN C/A 499202 NULL NULL

The above mentioned records delimiter is space. I need to extract the records from the 4th column where if any record prefix with 5, then I need to extract the entire records from that file. Please guide me how can I extract the prefix '5' from the 4th column.

Any help is really appreciated.

Expected output:
Code:
220 IN C/A 515013 NULL NULL 
220 IN C/A 515017 NULL NULL
225 IN C/A 515034 NULL NULL


Moderator's Comments:
Mod Comment Please use code tags, see PM.

Last edited by vbe; 02-13-2014 at 08:23 AM.. Reason: zaxxon's mod typo hehe...
# 2  
Old 02-13-2014
What have you tried so far?
# 3  
Old 02-13-2014
Thanks for your reply.

I have tried like below. But I did not get any result.

Code:
awk -F' ' $4='^5' file.txt

Please guide me how to handle this issue

Last edited by zaxxon; 02-14-2014 at 05:00 AM..
# 4  
Old 02-13-2014
Use regexp comparison operator:
Code:
awk '$4~/^5/' file

# 5  
Old 02-13-2014
Thanks Yoda! for your help at the right time.

I got my expected result.

Thanks once again Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract First character in Second column

Hi, I need to extract the first character of second column of my file. If the condition matches, then I need to print the 2nd and 3rd column as my output I tried below mentioned query but it was not working awk -F'|' '$2~/^5/' Sgn_group.txt File Name : Sgn_group.txt country... (2 Replies)
Discussion started by: suresh_target
2 Replies

2. Shell Programming and Scripting

[Solved] Replace character in 3rd column and leave 1rst and last

Hello to all, I have the following text where columns are separated by spaces. I want to have the 3rd column separating 3 strings with 2 "_" in the format below: LeftSring_CentralString_RightString So, in 3rd column I want to replace all "_" with "-", except the first and last "_" The... (5 Replies)
Discussion started by: Ophiuchus
5 Replies

3. Shell Programming and Scripting

Remove the first character from the fourth column only if the column has four characters

I have a file as follows ATOM 5181 N AMET K 406 12.440 6.552 25.691 0.50 7.37 N ATOM 5182 CA AMET K 406 13.685 5.798 25.578 0.50 5.87 C ATOM 5183 C AMET K 406 14.045 5.179 26.909 0.50 5.07 C ATOM 5184 O MET K... (14 Replies)
Discussion started by: hasanabdulla
14 Replies

4. Shell Programming and Scripting

[Solved] Sorting a column based on another column

hello, I have a file as follows: F0100010 A C F0100040 A G BTA-28763-no-rs 77.2692 F0100020 A G F0100030 A T BTA-29334-no-rs 11.4989 F0100030 A T F0100020 A G BTA-29515-no-rs 127.006 F0100040 A G F0100010 A C BTA-29644-no-rs 7.29827 F0100050 A... (9 Replies)
Discussion started by: Homa
9 Replies

5. UNIX for Dummies Questions & Answers

[Solved] Deleting all rows where the first column equals the second column

Hi, I have a tab delimited text file where the first two columns equal numbers. I want to delete all rows where the value in the first column equals the second column. How do I go about doing that? Thanks! Input: 1 1 ABC DEF 2 2 IJK LMN 1 2 ZYX OPW Output: 1 2 ZYX OPW (2 Replies)
Discussion started by: evelibertine
2 Replies

6. Shell Programming and Scripting

replace by match on fourth column

Hi friends, My input file is this way chr1 100 200 "abc" chr1 350 400 "abc" chr2 450 600 "def" chr2 612 780 "def" How do I make this file into chr1 100 400 "abc" chr2 450 780 "def" This is basically matching on the fourth column and taking the minimum of second column and the... (4 Replies)
Discussion started by: jacobs.smith
4 Replies

7. Emergency UNIX and Linux Support

[Solved] Extract records based on a repeated column value

Hi guys, I need help in making a command to find some data. I have multiple files in which multiple records are present.. Each record is separated with a carriage return and in each record there are multiple fields with each field separated by "|" what i want is that I want to extract... (1 Reply)
Discussion started by: m_usmanayub
1 Replies

8. Shell Programming and Scripting

Use awk to have the fourth column with spaces

Hi Gurus, We have a ftpserver from which we do a dir command and output it to a local file. The content of the ftpfile is: 07-15-09 06:06AM 5466 ABC_123_ER19057320090714082723.ZIP 07-15-09 06:07AM 3801 ABC_123_ER19155920090714082842.ZIP 07-15-09 06:07AM ... (14 Replies)
Discussion started by: donisback
14 Replies

9. Shell Programming and Scripting

How to manipulate first column and reverse the line order in third and fourth column?

How to manipulate first column and reverse the line order in third and fourth column as follws? For example i have a original file like this: file1 0.00000000E+000 -1.17555359E-001 0.00000000E+000 2.00000000E-002 -1.17555359E-001 0.00000000E+000 ... (1 Reply)
Discussion started by: Max Well
1 Replies

10. Shell Programming and Scripting

How to extract first column with a specific character

Hi All, Below is the sample data of my files: O|A|571000689|D|S|PNH|S|SI sadm|ibscml1x| I|A|571000689|P|S|PNH|S|SI sadm|ibscml1x| O|A|571000689|V|S|PNH|S|SI sadm|ibscml1x| S|C|CAM|D|S|PNH|R|ZOA|2004 bscml1x| ... (3 Replies)
Discussion started by: selamba_warrior
3 Replies
Login or Register to Ask a Question