Finding features a test file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding features a test file
# 1  
Old 11-27-2011
Finding features a test file

Hey guys,

I'm extracting mobile features from a file and the structure is this:

Code:
Push-to-talk  
Feature  
No  
Support for IP telephony  
Feature  
Yes  
Built-in SIP stack  
Feature  
Yes  
Support via software  
Feature  
Yes  
Support for Microsoft Exchange  
Feature  
Yes  
UMA  
Feature  
No  
WAP  
Feature  
Yes
Weight  
Feature  
129 g
Display  
Feature  
Colour  
Number of colours  
Feature  
262144
Display technology  
Feature  
LCD

I have a list of features also and want to copy the features to another file, so this is my feature list:

Code:
Push-to-talk  
Support for IP telephony  
Built-in SIP stack  
Support via software 
Bluetooth 
Support for Microsoft Exchange  
UMA  
WAP  
Weight
Size  
Display  
Number of colours  
Display technology
Resolution

and I want the output file to be like this:

Code:
No  
Yes  
Yes  
Yes
null  
Yes  
No  
Yes
129 g
null
Colour  
262144
LCD
null

as you could see there are some features in the feature list that are not in the input file. so in the output there would be null for that feature.

I used a bash code to just copy the values after the "Feature" word, but as you could see there are features that are not found in the input file and I need a null value for them.

Could you please help me about that?

thnx
# 2  
Old 11-27-2011
If you are working with a shell script, try the join command. It takes two sorted input files and outputs an SQL like result that joins selected fields from records with matching keys. Take the first file and "roll up" the three line groups to individual lines. Join the second file to this result. Join has options to output non-matched lines as well as matching lines so you can find the "null" results. The key issue can get a little tricky, so I usually construct a key in front of the lines being joined that is extracted/built from the line content.
# 3  
Old 11-27-2011
yes, I think the solution with bash is hard Smilie
I think doing it with perl is easier, but i'm not good in perl, do you have any idea how to do it with perl?
# 4  
Old 11-27-2011
Try this...
Code:
awk '{gsub(/[ ]*$/,"")}NR==FNR{x=$0;getline;getline;a[x]=$0;next}{print a[$0]?a[$0]:"null"}'  file1 file2

file1 is the mobile feature
file2 is the feature list

HTH
--ahamed
This User Gave Thanks to ahamed101 For This Post:
# 5  
Old 11-27-2011
Quote:
Originally Posted by ahamed101
Try this...
Code:
awk '{gsub(/[ ]*$/,"")}NR==FNR{x=$0;getline;getline;a[x]=$0;next}{print a[$0]?a[$0]:"null"}'  file1 file2

file1 is the mobile feature
file2 is the feature list

HTH
--ahamed
Thank you so much ahamed, the code worked great, but the thing is i didn't understand the code and how it works Smilie

I have some extra line of description between some texts, so your script may not work,

could catch the second line after the match to the output file, or maybe I could delete all of the "Feature" words and the code catch the line after as the output.

could you pleade help me with that?

---------- Post updated at 03:19 PM ---------- Previous update was at 03:16 PM ----------

and there some features in the input that should not be catched
# 6  
Old 11-27-2011
Paste the actual input file, that will be helpful.

--ahamed
# 7  
Old 11-27-2011
Quote:
Originally Posted by ahamed101
Paste the actual input file, that will be helpful.

--ahamed
Hi,

I posted the reply but it should be checked by the moderator Smilie

---------- Post updated at 04:48 PM ---------- Previous update was at 04:44 PM ----------

I would post it in a new topic

---------- Post updated at 05:20 PM ---------- Previous update was at 04:48 PM ----------

https://www.unix.com/shell-programmin...xing-file.html
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Hit multiple URL from a text file and store result in other test file

Hi, I have a problem where i have to hit multiple URL that are stored in a text file (input.txt) and save their output in different text file (output.txt) somewhat like : cat input.txt http://192.168.21.20:8080/PPUPS/international?NUmber=917875446856... (3 Replies)
Discussion started by: mukulverma2408
3 Replies

2. Shell Programming and Scripting

Prefixing test case methods with letter 'test'

Hi, I have a Python unit test cases source code file which contains more than a hundred test case methods. In that, some of the test case methods already have prefix 'test' where as some of them do not have. Now, I need to add the string 'test' (case-sensitive) as a prefix to those of the... (5 Replies)
Discussion started by: royalibrahim
5 Replies

3. Shell Programming and Scripting

Problem in test file operator on a ufsdump archive file mount nfs

Hi, I would like to ask if someone know how to test a files if exist the file is a nfs mount ufsdump archive file.. i used the test operator -f -a h almost all test operator but i failed file1=ufs_root_image.dump || echo "files doesn't exist && exit 1 the false file1 is working but... (0 Replies)
Discussion started by: jao_madn
0 Replies

4. Shell Programming and Scripting

How to check weather a string is like test* or test* ot *test* in if condition

How to check weather a string is like test* or test* ot *test* in if condition (5 Replies)
Discussion started by: johnjerome
5 Replies

5. Shell Programming and Scripting

Test on string containing spacewhile test 1 -eq 1 do read a $a if test $a = quitC then break fi d

This is the code: while test 1 -eq 1 do read a $a if test $a = stop then break fi done I read a command on every loop an execute it. I check if the string equals the word stop to end the loop,but it say that I gave too many arguments to test. For example echo hello. Now the... (1 Reply)
Discussion started by: Max89
1 Replies

6. AIX

AIX OS Features versus Solaris OS Features

Hi Unix Experts, I like to compile and compare all the features that AIX OS (541L) and Solaris OS (Solaris 10) provide. If somebody can shed on this topic would be highly appreciated. Thank you, Khan (0 Replies)
Discussion started by: hkhan12
0 Replies
Login or Register to Ask a Question