Like to select text in a From/To list


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Like to select text in a From/To list
# 1  
Old 10-04-2012
Like to select text in a From/To list

Hi

I need help to configure AWK to find a string based From/To filed

I have a table like this
Code:
0A00 - 0AFF Nuts
0B00 - 0BFF Bolt

If I have in a program a value like "0B22" I wold like to get "Bolt" in return.
List are in Hex

Still try to learn AWK Smilie
# 2  
Old 10-04-2012
i think this will work for Hex..
try

Code:
awk -v VM="0B22" 'VM > $1 && VM < $3{print $NF}' file

This User Gave Thanks to pamu For This Post:
# 3  
Old 10-04-2012
Quote:
Originally Posted by pamu
i think this will work for Hex..
try

Code:
awk -v VM="0B22" 'VM > $1 && VM < $3{print $NF}' file

This won't work if the case of the hex characters is mixed. Below code will work in this case:
Code:
awk -vx=0b22 'NR==1{x=strtonum("0x"x)}{$1=strtonum("0x"$1);$3=strtonum("0x"$3)}x>=$1&&x<=$3{print $4}' file
awk -vx=0B22 'NR==1{x=strtonum("0x"x)}{$1=strtonum("0x"$1);$3=strtonum("0x"$3)}x>=$1&&x<=$3{print $4}' file

This User Gave Thanks to bartus11 For This Post:
# 4  
Old 10-04-2012
And if you don't have this gawk function, try:
Code:
awk -v VM="0B22" 'BEGIN{n=sprintf("%d","0x"VM)}
{one=sprintf("%d","0x"$1)
three=sprintf("%d","0x"$3)
if(n>one&&n<three) print $NF}' file


Last edited by elixir_sinari; 10-04-2012 at 09:52 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Select row from file and text

Hi all! I would like to solve a problem but I have no clue of how do it!I will be grateful if someone could help me! Briefly I have a big file like this: >ENSMUSG00000000204 | ENSMUST00000159637 GGCGAGGCTTACGCCATTTTACCTCAGCGAGCATTCATAAAGCTGCGAGCATTCATACAG >ENSMUSG00000000204 |... (3 Replies)
Discussion started by: giuliangiuseppe
3 Replies

2. UNIX Desktop Questions & Answers

Script to select a file from a list

i m trying to write a script that will print all the txt files at /home/ directory and will allow a selection of a file and then print the file name. this is what i wrote so far: echo "please select the file from the list " list=$(ls -f *.txt /home/) array=( ) for machine in $list doat... (1 Reply)
Discussion started by: boaz733
1 Replies

3. Shell Programming and Scripting

search & select text

hi people; from my file:... ... ... 101221-18:45:17 192.168.1.1 1.0 PortNodeModel ========================================================= Object Attribute Value ========================================================= SectorPort=3 switchport 20 SectorPort=1 switchport 10 SectorPort=2... (12 Replies)
Discussion started by: gc_sw
12 Replies

4. UNIX for Dummies Questions & Answers

How to select text within the second ()?

Hello, Can someone advise me how to select the text within the second bracket of a string in shell script? For example, the input file: some message (string A) some message (string B) some message (string C) some message (string D) some message (string E) The number of bracket is random... (4 Replies)
Discussion started by: hanul
4 Replies

5. Shell Programming and Scripting

select data from list

Hi! My data file contains a two columns list. It looks like: 1 3.789 2 6.789 3 7.890 4 8.900 5 6.789 6 1.987 7 10.987 8 2.987 9 0.987 I would like to create a new list using the awk command, just selecting data from the second column but also printing the first column. Let say I select... (3 Replies)
Discussion started by: cris48
3 Replies

6. Shell Programming and Scripting

select some text from a test dependng on pattern

I have some absolute file location $INSTALL_BASEPATH/onereview-5.0/resources/commons-messages/commonmessages_default.properties $INSTALL_BASEPATH/onereview-5.0/orv-deploy/config-console.war/WEB-INF/classes/com/connectiva/configuration/console/resource/configurationBundle.properties I need to... (3 Replies)
Discussion started by: mnmonu
3 Replies

7. Shell Programming and Scripting

random select text file ranamed

i want to need script.. source.txt /home/user1/public_html/test3 /home/user90/public_html/test9 . . . /home/user650/public_html/test000 read source.txt and cd /home/user**/public_html/*** and there is 1.txt, 2txt ~~25.txt and select 6 text files randomly among the... (4 Replies)
Discussion started by: topic32428285
4 Replies

8. UNIX for Dummies Questions & Answers

Awk - select from a list

Hi all, I am trying to select some columns from a file, based on the list of values. Would like to know how best I can achive this. If coulmn 1 has a value of 57 then print the ist column (This works) awk -F' ' '{if ( $1 == 57 ) {print $1}}' file.txt Now my requirement is that I have to... (14 Replies)
Discussion started by: simha77777
14 Replies

9. UNIX for Dummies Questions & Answers

Select text within matching ( ) bracket

Hi, I am looking for a simple command to select text within a open bracket "(" and a matching close bracket ")" and output the within-bracket-text to a file. This function is similar to the common vi select a range of text with "(" to ")" but not sure how to run the same function in command... (4 Replies)
Discussion started by: cursive
4 Replies

10. Shell Programming and Scripting

reappearing menu list using select

is there a way I can make the menu list reappear when I use select ? ----- menulist="Change_title Remove_tag Change_tag Add_line Quit" select word in $menulist #change_title remove_tag change_tag add_line quit do case $word in # first menu option Change Title ... (9 Replies)
Discussion started by: forever_49ers
9 Replies
Login or Register to Ask a Question