remove 1st and last last values of a key


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting remove 1st and last last values of a key
# 1  
Old 08-23-2010
remove 1st and last last values of a key

For every specific keys i.e. 1st and 4th columns (a1 and ABC_001144992) remove 1st and last value (bold ones - 87942437 and 87952030 ) and print remaining
input

Code:
a1 	87942437 	87943147 	1E 	ABC_001144992
a1 	87945162 	87945276 	2E 	ABC_001144992
a1 	87949524 	87952030 	3E 	ABC_001144992
a1 	89967353 	89968253 	1E 	ABC_201644
a1 	90111618	 90111750 	2E 	ABC_201644
a1 	90112369 	90112457 	3E 	ABC_201644
a1	 90112712 	90112932 	4E 	ABC_201644
a1 	90114701 	90116577 	5E 	ABC_201644

output

Code:
a1 	87943147 	87945162 	1I 	ABC_001144992
a1	 87945276 	87949524 	2I 	ABC_001144992
a1 	89968253 	90111618 	1I 	ABC_201644
a1 	90111750 	90112369 	2I 	ABC_201644
a1 	90112457 	90112712 	3I 	ABC_201644
a1 	90112932 	90114701 	4I 	ABC_201644

# 2  
Old 08-23-2010
Untested:

Code:
awk 'p {
  n = split(p, t)
  if (t[n] == $NF) 
    print t[1], t[3], $2, t[4], t[5]
  }
{ p = $0 }
  ' infile

This User Gave Thanks to radoulov For This Post:
# 3  
Old 08-23-2010
A minor tweak to radoulov's solution which fixes the 4th column:
Code:
awk 'p {
  n = split(p, t)
  if (t[n] == $NF) 
    print t[1], t[3], $2, ++i"I", t[5]
  else
    i=0
  }
{ p = $0 }
  ' infile

This User Gave Thanks to alister For This Post:
# 4  
Old 08-23-2010
Could you please explain the code ?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Taking key values from one file and extracting values from another file

Hi, I have two files with values in both. File1: cat 2 3 dog 4 5 elephant 6 7 camel 2 3 File2: ----+--gkf;ajf= ---+---- +----- cat -------=----+ 3 | 4 ----- dog ------++-- 5 | 9 ----++-- elephant | 5 | 7 ---++ camel ------ ++++_---- || 8 | 9 I want the final file as: cat 4... (1 Reply)
Discussion started by: npatwardhan
1 Replies

2. Shell Programming and Scripting

Fetch the values based on a Key using awk from single file

Hi, Please help to fetch the values for a key from below data format in linux. Sample Input Data Format 11055005|PurchaseCondition|GiftQuantity|1 11055005|PurchaseCondition|MinimumPurchase|400 11055005|GiftCatalogEntryIdentifier|Id|207328014 11429510|PurchaseCondition|GiftQuantity|1... (2 Replies)
Discussion started by: mohanalakshmi
2 Replies

3. Shell Programming and Scripting

Show distinct values of a key from a single line

Hi All, I am newbie to linux. Can somebody help me with following requirement. I have one huge line. I have to find out particular key/value pair to see the distinct value of that key. Portion of the String:- <?xml version="1.1" encoding="UTF-8"?> <Data><Val Ti="1342750845538" Du="0"... (5 Replies)
Discussion started by: kmajumder
5 Replies

4. Shell Programming and Scripting

Extract key words and print their values

Input file (HTTP request log file): GET... (2 Replies)
Discussion started by: buptwy
2 Replies

5. Shell Programming and Scripting

extract key values

I am parsing a log with key values spread all over in the following fashion: TEST 1 SCHEME 12 SET EMPTY VARLEN SET TEST 1201 PARAM1 EMTY PARAM2 SET SCHEME 12 REFRESH TEST 8 I need to extract test number, my result should be 1 1201 8 I use awk for processing this log and use... (4 Replies)
Discussion started by: migurus
4 Replies

6. UNIX for Dummies Questions & Answers

Remove VI encryption key from file

Hi There, I have set encryption key to my file using :X command. Now that I no more need encryption key to the file, I just want to delete/remove the encryption key. I have gone through many source but in vain. None of the source provided me with the solution that I am looking for. I... (2 Replies)
Discussion started by: grc
2 Replies

7. Shell Programming and Scripting

Print a key with its all values using awk/others

input COL1 a1 b1 c1 d1 e1 f1 C1 10 10 10 100 100 1000 C2 20 20 200 200 200 2000 output C1 a1 10 1 C1 b1 10 1 C1 c1 10 1 C1 d1 100 2 C1 e1 100 2 C1 f1 1000 3 C2 ... (12 Replies)
Discussion started by: ruby_sgp
12 Replies

8. Shell Programming and Scripting

How to pick values from column based on key values by usin AWK

Dear Guyz:) I have 2 different input files like this. I would like to pick the values or letters from the inputfile2 based on inputfile1 keys (A,F,N,X,Z). I have done similar task by using awk but in that case the inputfiles are similar like in inputfile2 (all keys in 1st column and values in... (16 Replies)
Discussion started by: repinementer
16 Replies

9. Shell Programming and Scripting

How to delete ctrl key values in a given string?

Hi all, My query is... in the runtime, you are getting any input string. Unfortunately, you have pressed some ctrl keys or esc keys or arrow keys while typing input string. You can get the input value like that... input string as welcome^ So ,I want to remove those unwanted keys... (4 Replies)
Discussion started by: balan_mca
4 Replies

10. UNIX for Dummies Questions & Answers

Generating key values for leader records

All, I have a file with text as shown below. I want the o/p file with generated values in the first column as shown in the o/p file. Pls note that the size of my file is 6 GB. How do i do this ? Input file 999999abcdef 999999ghijkl 999999mnopq 777777rosesarered 777777skyisblue Output... (1 Reply)
Discussion started by: ajfaq
1 Replies
Login or Register to Ask a Question