Sponsored Content
Top Forums Shell Programming and Scripting find values between values in two different fields Post 302506765 by redse171 on Monday 21st of March 2011 11:24:55 PM
Old 03-22-2011
Data find values between values in two different fields

Hi,

I need help to find values between two different fields based on $6 (NUM) AND $1 (CD), within the same ID. The result should show the values between the NUMs which will be extracted from within $3 and $2 in data.txt file below.

data.txt
Code:
  ex    139    142    Sc_1000004    ID 4
  CD    139    142    Sc_1000004    ID 4    Num1
  sta   139    140    Sc_1000004
  ex    143    144    Sc_1000004    ID 4
  CD    148    150    Sc_1000004    ID 4    Num2
  ex    153    156    Sc_1000004    ID 4
  CD    153    156    Sc_1000004    ID 4    Num3
  sto   156    158    Sc_1000004

  ex    160    163    Sc_1000005    ID 5
  CD    160    163    Sc_1000005    ID 5    Num1
  sta   160    161    Sc_1000005
  ex    167    170    Sc_1000005    ID 5
  CD    167    170    Sc_1000005    ID 5    Num2
  ex    175    205    Sc_1000005    ID 5
  CD    175    205    Sc_1000005    ID 5    Num3
  sto   205    207    Sc_1000005

  ex    212    221    Sc_1000006    ID 6
  CD    212    221    Sc_1000006    ID 6    Num2
  sto   212    215    Sc_1000006
  ex    224    227    Sc_1000006    ID 6
  CD    224    227    Sc_1000006    ID 6    Num1
  sta   227    229    Sc_1000006

  ex    243    248    Sc_1000007    ID 7
  CD    243    248    Sc_1000007    ID 7    Num1
  sta   243    243    Sc_1000007
  ex    251    257    Sc_1000007    ID 7
  CD    251    257    Sc_1000007    ID 7    Num2
  ex    261    263    Sc_1000007    ID 7
  CD    261    263    Sc_1000007    ID 7    Num3
  sto   263    265    Sc_1000007

  ex    275    288    Sc_1000008    ID 8
  CD    275    288    Sc_1000008    ID 8    Num1
  sta   275    277    Sc_1000008

i want to have output like this:-
Code:
  NewVal    143 - 147     ID 4
  NewVal    151 - 152     ID 4
  NewVal    164 - 166     ID 5       
  NewVal    170 - 174     ID 5
  NewVal    222 - 223     ID 6
  NewVal    249 - 250     ID 7
  NewVal    257 - 260     ID 7

in the above output, for eg., "143 - 147" are the CD values extracted between NUM 1 and NUM 2. While "151 - 152" are the CD values extracted between NUM 2 and NUM 3 for ID 4 in the input file (data.txt)... and so on..but if there is only 1 NUM (such as NUM1 for ID 8), which means that only 1 CD exist for that ID, then no NewVal will be extracted.

I have thousands of values that i need to extract from hundreds of files like this Smilie. Would appreciate your kind help or advise to do this in awk or sed. Thanks...
 

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

plus values from two files differient fields.

Hi Everyone, I have two files: filea: Sun Jun 21 14:37:56 2009 1 2 3 Sun Jun 21 11:47:16 2009 2 3 4 fileb: Sun Jun 21 14:37:56 2009 1 2 3 Sun Jun 21 11:47:17 2009 33 44 55 The output is filec: Sun Jun 21... (4 Replies)
Discussion started by: jimmy_y
4 Replies

2. UNIX for Dummies Questions & Answers

distinct values of all the fields

I am a beginner to scripting, please help me in this regard. How do I create a script that provides a count of distinct values of all the fields in the pipe delimited file ? I have 20 different files with multiple columns in each file. I needed to write a generic script where I give the number... (1 Reply)
Discussion started by: vukkusila
1 Replies

3. Shell Programming and Scripting

distinct values of all the fields

I am a beginner to scripting, please help me in this regard. How do I create a script that provides a count of distinct values of all the fields in the pipe delimited file ? I have 20 different files with multiple columns in each file. I needed to write a generic script where I give the number... (2 Replies)
Discussion started by: vukkusila
2 Replies

4. Shell Programming and Scripting

Assigning fields values to different variables

Hi, I have this code: cat file.txt | awk -F, 'NR==1{print $6","$8","$10","$20","$21","$19}' > file.tmp VAR1=`cat file.tmp | cut -d "," -f1` VAR2=`cat file.tmp | cut -d "," -f2` VAR3=`cat file.tmp | cut -d "," -f3`; VAR4=`cat file.tmp | cut -d "," -f4`; VAR5=`cat... (1 Reply)
Discussion started by: Tr0cken
1 Replies

5. Shell Programming and Scripting

Need help in finding sum for values in 2 different fields

Hi there, I have 2 files in following format cat file_1 Storage Group Name: aaaa HBA UID SP Name SPPort ------- ------- ------ 0 21 Storage Group Name: bbbb HBA UID... (2 Replies)
Discussion started by: jpkumar10
2 Replies

6. Shell Programming and Scripting

How to find the X highest values in a list depending on the values of another list with bash/awk?

Hi everyone, This is an exemple of inpout.txt file (a "," delimited text file which can be open as csv file): ID, Code, Value, Store SP|01, AABBCDE, 15, 3 SP|01, AABBCDE, 14, 2 SP|01, AABBCDF, 13, 2 SP|01, AABBCDE, 16, 3 SP|02, AABBCED, 15, 2 SP|01, AABBCDF, 12, 3 SP|01, AABBCDD,... (1 Reply)
Discussion started by: jeremy589
1 Replies

7. Shell Programming and Scripting

How to get the values of multipledot(.) separated fields?

Hello, I have a file which has the following contents : thewall............0000000000200000 kmemfreelater......0000000000000000 kmemgcintvl........0000000000000002 kmeminuse..........00000000223411C0 allocated..........0000000029394000 bucket.......... @.F1000A02800C2158 The mentioned... (4 Replies)
Discussion started by: rahul2662
4 Replies

8. Shell Programming and Scripting

Find duplicate values in specific column and delete all the duplicate values

Dear folks I have a map file of around 54K lines and some of the values in the second column have the same value and I want to find them and delete all of the same values. I looked over duplicate commands but my case is not to keep one of the duplicate values. I want to remove all of the same... (4 Replies)
Discussion started by: sajmar
4 Replies
MODINFO(8)																MODINFO(8)

NAME
modinfo - program to show information about a Linux Kernel module SYNOPSIS
modinfo [ -0 ] [ -F field ] [ -k kernel ] [ modulename|filename... ] modinfo -V modinfo -h DESCRIPTION
modinfo extracts information from the Linux Kernel modules given on the command line. If the module name is not a filename, then the /lib/modules/version directory is searched, as is also done by modprobe(8) when loading kernel modules. modinfo by default lists each attribute of the module in form fieldname : value, for easy reading. The filename is listed the same way (although it's not really an attribute). This version of modinfo can understand modules of any Linux Kernel architecture. OPTIONS
-V --version Print the modinfo version. -F --field Only print this field value, one per line. This is most useful for scripts. Field names are case-insenitive. Common fields (which may not be in every module) include author, description, license, parm, depends, and alias. There are often multiple parm, alias and depends fields. The special field filename lists the filename of the module. -k kernel Provide information about a kernel other than the running one. This is particularly useful for distributions needing to extract information from a newly installed (but not yet running) set of kernel modules. For example, you wish to find which firmware files are needed by various modules in a new kernel for which you must make an initrd/initramfs image prior to booting. -0 --null Use the ASCII zero character to separate field values, instead of a new line. This is useful for scripts, since a new line can theo- retically appear inside a field. -a -d -l -p -n These are shortcuts for author, description, license. parm and filename respectively, to ease the transition from the old modutils modinfo. COPYRIGHT
This manual page originally Copyright 2003, Rusty Russell, IBM Corporation. Maintained by Jon Masters and others. SEE ALSO
modprobe(8) 2010-03-01 MODINFO(8)
All times are GMT -4. The time now is 04:24 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy