Need last column form file ..


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need last column form file ..
# 1  
Old 09-10-2012
MySQL Need last column form file ..

Input File A

Code:
A019 BXP_0_1 RRB12 (16,429)
A019 BXP_1_1 RRB12 (17,431)
A019 BXP_2_1 RRB12 (17,431)
A021 BXP_0_1 RRB12 (16,316)
A021 BXP_1_1 RRB12 (,315)
A021 BXP_2_1 RRB12 
A022 BXP_0_1 RRU12 (16,200)
A022 BXP_1_1 RRU12 (17,198)
A022 BXP_2_1 RRU12 (17,198)
A024 BXP_0_1 RRU12 (16,283)
A024 BXP_1_1 RRU12 (17,282)
A024 BXP_2_1 RRU12 (17,282)


Output File B

Code:
A019 BXP_0_1 RRB12 429
A019 BXP_1_1 RRB12 431
A019 BXP_2_1 RRB12 431
A021 BXP_0_1 RRB12 316
A021 BXP_1_1 RRB12 315
A021 BXP_2_1 RRB12 N/I
A022 BXP_0_1 RRU12 200
A022 BXP_1_1 RRU12 198
A022 BXP_2_1 RRU12 198
A024 BXP_0_1 RRU12 283
A024 BXP_1_1 RRU12 282
A024 BXP_2_1 RRU12 282

Thanks
# 2  
Old 09-10-2012
This is a bit terse. I am guessing the first file specifies acceptable pass ranges for the second file.

Do you need to preserve order in the second file, or can we sort to make it more trivial. You can use 'join' on sorted files to match those keys, and process the join output in a "while read v1 v2 v3 ....".

Else, you need to store the first file before decoding and testing each line of the second, using associative vector hash maps to store the limits for lookup by the first three fields.

Also, you need some logic to deal with open ends in ranges, such as (0,0) for no numeric range, and testing limits only if limit not zero.
# 3  
Old 09-10-2012
Assuming you just want to strip the ellipses and thousands from the last column, try
Code:
sed -E 's/\([^,]*,(^\)+)\)/\1/' file

# 4  
Old 09-10-2012
MySQL

Still not get anything ....

Possible with using awk command
# 5  
Old 09-10-2012
'not get anything' as in no output?

What's your OS?

EDIT: Bah, yet another typo sneaked in. If you have GNU sed then this should work:
Code:
sed -E 's/\([^,]*,([^\)]+)\)/\1/' file


Last edited by CarloM; 09-10-2012 at 06:47 PM..
# 6  
Old 09-10-2012
Try awk (nawk for Solaris):

Code:
awk 'NF==4{gsub(/.*,/,"",$4);gsub(/)/,"",$4)} NF==3{$4="N/I"} 1' infile

# 7  
Old 09-10-2012
Previous post is cool and here is another way

Code:
awk -F'[(,)]' '{ str = "N/A"; if (NF-1>0) { print $1 $(NF-1) } else { print $NF str } }' infile


Last edited by Franklin52; 09-11-2012 at 04:01 AM.. Reason: Please use code tags for data and code samples
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to search a particular String form a file a write to another file using perl script

I have file which contains a huge amount of data. I need to search the pattern Message id. When that pattern is matched I need to get abcdeff0-1g6g-91g3-1z2z-2mm605m90000 to another file. Kindly provide your input. File is like below Jan 11 04:05:10 linux100 |NOTICE... (2 Replies)
Discussion started by: Raysf
2 Replies

2. UNIX for Dummies Questions & Answers

Creating a two column list of date pairs form a single column list

Hi all, looking for some help here. I'm what you'd call a dirty programmer. my shell scripts might be ugly, but they (usually) function... Say I have a single column text file with a list of dates (yyyymmdd) that represent the elevation of a point on that date (I work with land subsidence, so... (2 Replies)
Discussion started by: jbrandt1979
2 Replies

3. Shell Programming and Scripting

Transpose Data form Different form

HI Guys, I have data in File A.txt RL03 RL03_A_1 RL03_B_1 RL03_C_1 RL03 -119.8 -119.5 -119.5 RL07 RL07_A_1 RL07_B_1 RL07_C_1 RL07 -119.3 -119.5 -119.5 RL15 RL15_A_1 RL15_C_1 RL15 -120.5 -119.4 RL16... (2 Replies)
Discussion started by: asavaliya
2 Replies

4. Shell Programming and Scripting

create txt file form data file and add some line on it

Hi Guys, I have file A.txt File A Data AK1521 AK2536 AK3164 I want create text file of all data above and write some data on each file. want Output on below folder /home/kka/out AK1521.txt Hi Welocme (3 Replies)
Discussion started by: asavaliya
3 Replies

5. Shell Programming and Scripting

Taking largest (negative) number from column of coordinates and adding positive form to every other

Hello all, I'm new to the forums and hope to be able to contribute something useful in the future; however I must admit that what has prompted me to join is the fact that currently I need help with something that has me at the end of my tether. I have a PDB (Protein Data Bank) file which I... (13 Replies)
Discussion started by: crunchgargoyle
13 Replies

6. Shell Programming and Scripting

Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2

Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2 file 1 sample SNDK 80004C101 AT XLNX 983919101 BB NETL 64118B100 BS AMD 007903107 CC KLAC 482480100 DC TER 880770102 KATS ATHR 04743P108 KATS... (7 Replies)
Discussion started by: rydz00
7 Replies

7. UNIX for Advanced & Expert Users

need to get single column form csv file

hi 2 all i need to get single column from one csv file anyone help me ! >cat file.csv name,age x,1 y,2 z,3 Use code tags please, ty. in this "file.csv" file i need only name column can u help me !:b::b: (7 Replies)
Discussion started by: ponmuthu
7 Replies

8. Shell Programming and Scripting

Changing one column of delimited file column to fixed width column

Hi, Iam new to unix. I have one input file . Input file : ID1~Name1~Place1 ID2~Name2~Place2 ID3~Name3~Place3 I need output such that only first column should change to fixed width column of 15 characters of length. Output File: ID1<<12 spaces>>Name1~Place1 ID2<<12... (5 Replies)
Discussion started by: manneni prakash
5 Replies

9. UNIX for Advanced & Expert Users

Changing Unix form to Microsoft Word form to be able to email it to someone.

Please someone I need information on how to change a Unix form/document into a microsoft word document in order to be emailed to another company. Please help ASAP. Thankyou :confused: (8 Replies)
Discussion started by: Cheraunm
8 Replies
Login or Register to Ask a Question