indexing a file


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
# 1  
indexing a file

hello guys,

I have a file like this:

input.dat

Code:
Push-to-talk 
No
Coonection
IP support 
Support for IP telephony 
Yes 
Built-in SIP stack 
Yes 
Support via software 
Yes 
Microsoft
Support for Microsoft Exchange 
Yes 
UMA 
No 
Internet
Internet connection
WAP 
Yes 
Weight 
129 g 
GUI type
Display 
Colour 
Number of colours 
262144 
Display technology 
LCD
Display Resolution
Screen resolution  
320x480 pixels  
Screen size  
3.2 inches  
Touchscreen  
Yes  
Simultaneous touch points  
3+ Multi-touch  
Type of technology  
Capacitive

and the feature list is:

featureList.dat

Code:
Speaker
Support for IP telephony 
Support for Microsoft Exchange 
UMA 
WAP 
Weight 
Bluetooth
Dimension
Display technology 
Screen resolution  
Screen size  
Touchscreen  
Type of technology
USB connsection


and the desired output is:

output.dat:


Code:
null
Yes
Yes
No
Yes
129 g
null
null
LCD 
320x480 pixels
3.2 inches
Yes
Capacitive
null

I want to see what are the values of the features in the input file (features have their values in the line below them)

if the feature does not exist then the value would be "null"

there are some features in the input that are not in the featureList.dat, so just the desired features are the subject for the extraction.

I came up to this code by the help of Ahamed, but I have problem with it Smilie

Code:
awk '{gsub(/[ ]*$/,"")}NR==FNR{x=$0;getline;getline;a[x]=$0;next}{print a[$0]?a[$0]:"null"}'  file1 file2

# 2  
Okay, but what problem do you have?
# 3  
if I have some extra lines between features like the input file above, all of the output lines would be "null" Smilie

---------- Post updated at 06:18 PM ---------- Previous update was at 05:31 PM ----------

do you have any other idea?
# 4  
Try this...
Code:
#!/bin/bash
while read line
do
        val=$( grep -A1 "$line" file1 | tail -1 )
        echo ${val:-null}
done < file2

In case your grep doesn't support -A option, then replace the grep line with any of these
Code:
val=$( sed -n "/$line/{n;p;q}" file1 )
#or
val=$( awk '{if($0~srch){getline;print;exit}}' srch="$line" file1 )

HTH
--ahamed

Last edited by ahamed101; 11-27-2011 at 05:23 PM..
This User Gave Thanks to ahamed101 For This Post:
# 5  
hey ahamed,

thnx, it worked, but didn't show the last null, I don't know why!
# 6  
I am getting it...
Code:
root@bt:/tmp# ./run
null
Yes
Yes
No
Yes
129 g
null
null
LCD
320x480 pixels
3.2 inches
Yes
Capacitive
null

--ahamed
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #871
Difficulty: Medium
Hello World in Lisp is coded as: [ print "Hello world" ]
True or False?

8 More Discussions You Might Find Interesting

1. What is on Your Mind?

Your site has been switched to Mobile First Indexing

Well, Google throws the web a curve ball again: I thought I was going to get a break from coding; but no..... https://www.unix.com/members/1-albums215-picture1240.png (15 Replies)
Discussion started by: Neo
15 Replies

2. UNIX for Dummies Questions & Answers

Single Liner for indexing

Hello, This is pretty simple, I`m looking for a faster and better method than brute force that I`m doing. I have a 20GB file looks like Name1,Var1,Val1 Name1,Var2,Val2 Name2,Var1,Val3 Name2,Var2,Val4 I want 3 files. Nameindex 1 Name1 2 Name2 ... (2 Replies)
Discussion started by: senhia83
2 Replies

3. Shell Programming and Scripting

Indexing Variable Names

Hi All I think I might have bitten off more than I can chew here and I'm hoping some of you guys with advanced pattern matching skills can help me. What I want to do is index the occurrence of variable names within a library of scripts that I have. Don't ask why, I'm just sad like that... ... (3 Replies)
Discussion started by: bbq
3 Replies

4. Shell Programming and Scripting

Split a file using 2-D indexing system

I have a file and want to split it using a 2-D index system for example if the file is p.dat with 6 data sets separated by ">". I want to set nx=3, ny=2. I need to create files p.dat.1.1 p.dat.1.2 p.dat.1.3 p.dat.2.1 p.dat.2.2 p.dat.2.3 I have tried using a single index and want... (3 Replies)
Discussion started by: kristinu
3 Replies

5. UNIX for Dummies Questions & Answers

awk, array indexing

cat filename|nawk ' { FS="="; if (!a++ == 0) print $0 } ' can anyone plz explain how does array inexing works,how it is evaluating if (!a++ == 0)?? (2 Replies)
Discussion started by: dreamzalive
2 Replies

6. Shell Programming and Scripting

indexing list of words in a file

Hey all, I'm doing a project currently and want to index words in a webpage. So there would be a file with webpage content and a file with list of words, I want an output file with true and false that would show which word exists in the webpage. example: Webpage content data.html ... (2 Replies)
Discussion started by: Johanni
2 Replies

7. Shell Programming and Scripting

[ask]filtering file to indexing...

dear all, i have file with format like this file_master.txt 20110212|231213|rio|apri|23112|222222 20110212|312311|jaka|dino|31223|543234 20110301|343322|alfan|budi|32131|333311 ... i want filter with output like this index_nm.txt rio|apri jaka|dino ... index_years.txt 20110212... (7 Replies)
Discussion started by: zvtral
7 Replies

8. Shell Programming and Scripting

Array indexing in shell

Hi , I have 4 array as below Input: servernames=(10.144.0.129 10.144.0.130 10.144.0.131) subfolder_129=(PSTN_SigtranCamel_03 PSTN_SigtranCamel_04 PSTN_SigtranCamel_05) subfolder_130=(SigtranCamel_11 SigtranCamel_12 SigtranCamel_13 SigtranCamel_14 SigtranCamel_15)... (4 Replies)
Discussion started by: sushmab82
4 Replies

Featured Tech Videos