Extracting fetching values


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extracting fetching values
# 1  
Old 11-07-2011
Extracting fetching values

I have a file like this

Code:
############################################
# ParentFolder  Flag   SubFolders

Colateral        1      Source1/Checksum
CVA              1      Source1/Checksum
Test	         1      VaR/Checksum
Test2            1      SVaR/Checksum
FX               1      Checksum

I have two requirement one which I did with little help on counter but the this I couldn't figure it out how to make it possible.

Requirement

Subfolder column
if they have multiple values separated by "/" e.g. <muliti1>/<multi2>/<multi3>/...<multin> for a particular parent <parent>
o/p should look like
Code:
1.	<parent>/<muliti1>
2.	<parent>/<muliti1>/<multi2>/
3.	<parent>/<muliti1>/<multi2>/<multi3>
....
...
n.	<parent>/<muliti1>/<multi2>/<multi3>/...<multin>


So in this case O/p should looklike

Code:
1.	Colateral/Source1
2.	Colateral/Source1/Checksum
etc
5.	Test/VaR
6.	Test/VaR/Checksum
etc
9.	FX/Checksum

# 2  
Old 11-07-2011
Try this...
Code:
#!/bin/bash
awk '/^#/{next}
{
        split($3,arr,"/")
        for(i=1;i<=length(arr);i++){
                val=val"/"arr[i]
                print ++j".\t"$1""val
        }
        val=""
}' input_file

--ahamed
# 3  
Old 11-07-2011
nawk -f manas.awk myInput
manas.awk:
Code:
/^[^#]/ && NF {
  n=split($NF, a, "/")
  s=""
  for(i=1;i<=n;i++) {
    s=(!s)?a[i]:s "/" a[i]
    printf("%d. %s/%s\n", ++c,$1,s)
  }
}

# 4  
Old 11-08-2011
thanks Vgersh99 and Ahamed for your sweet reply.
Actually I did the same as Ahmed but mine wasn't working . As my script was n't looping thru properly.

Ahmed could you please explain me role of next , why I'm getting different resultsets ,
Code:
awk ' /^[^#]/ {next} {c=split($3,a,"/") ;for(n=1; n<=c; ++n) {print i++". "$1"/"a[n]}}' folderlist.txt  0. #/is
1. #/creating
2. #/By
3. #/:
4. #/Flag

Code:
 awk ' /^[^#]/ {c=split($3,a,"/") ;for(n=1; n<=c; ++n) {print i++". "$1"/"a[n]}}' folderlist.txt
0. Colateral/Source1
1. Colateral/Checksum
2. CVA/Source1
3. CVA/Checksum
4. Flexing/VaR
5. Flexing/Checksum
6. Flexing/SVaR
7. Flexing/Checksum
8. FX/Checksum

# 5  
Old 11-08-2011
Issue is with your print block...
Code:
awk ' /^[^#]/ {c=split($3,a,"/") ;for(n=1; n<=c; ++n) {val=val"/"a[n];print ++i". "$1 val}val=""}' input_file

--ahamed
# 6  
Old 11-08-2011
Ahmed, you are right. but I believe you didn't get my question properly,
why in my same executaion statement next behaves differently , above example is random.

like in first case it should ignore comment header block but instead it gives the result of header one and in second one if I remove next it gives the result set.

So could you enlighten me how next
Code:
/^[^#]/ {next}

is able to negate my call to remove header line ??

Please refer my example as stated earlier.
# 7  
Old 11-08-2011
awk '/^[^#]/ {next}...' means to ignore any line not starting with #
awk '/^#/ {next}...' means to ignore any line starting with #
awk '/^[^#]/ {process}...' means to process any line not starting with #

HTH
--ahamed
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extracting and comparing values

I was trying to extract value of g1 and p1 only inside the tags where t1 is "Reading C (bytes)" and comparing them to make sure p1 is always less than g1. Here is the Json file I'm using - File:- { "g1" : 1482568, "n1" : "v_4", "p1" : 0, "s1" : "RC", "t1" : "LM", } { "g1" :... (3 Replies)
Discussion started by: Mannu2525
3 Replies

2. 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

3. Shell Programming and Scripting

Fetching values in CSV file based on column name

input.csv: Field1,Field2,Field3,Field4,Field4 abc ,123 ,xyz ,000 ,pqr mno ,123 ,dfr ,111 ,bbb output: Field2,Field4 123 ,000 123 ,111 how to fetch the values of Field4 where Field2='123' I don't want to fetch the values based on column position. Instead want to... (10 Replies)
Discussion started by: bharathbangalor
10 Replies

4. Shell Programming and Scripting

help with fetching the values from perlscript

Hi, I have a perl script abc.pl.. #!/usr/bin/perl local ($buffer, @pairs, $pair, $name, $value, %FORM); # Read in text $ENV{'REQUEST_METHOD'} =~ tr/a-z/A-Z/; if ($ENV{'REQUEST_METHOD'} eq "POST") { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); }else {... (3 Replies)
Discussion started by: puneetkanchi
3 Replies

5. Shell Programming and Scripting

extracting values from configuration file

Dear All, i am new to shell scripting, I am working on embedded system based on linux.I am supposed to the read the configuration file and edit another file. presently I would like to read from the configuration file.It would be having values file one below. There is chance of entering... (6 Replies)
Discussion started by: Ratheendran
6 Replies

6. Shell Programming and Scripting

Error in fetching multiple row values into variables

Hello Team, In the below code....The variabe values are not fetch from input table into SELECT statements. =========================== #!/usr/bash DATABASE=XXXXX inputFILE=$1 db2 connect to $DATABASE TABLENAME=`echo $inputFILE|awk '{print $1}'` COLUMNNAME=`echo $inputFILE|awk... (2 Replies)
Discussion started by: rocking77
2 Replies

7. Shell Programming and Scripting

fetching values using awk and storing into array

hi all I am using awk utility to parse the file and fetching two different vaues from two different record of a record set. I am able to see the result, now i want to store the result and perform some check of each values form database to mark valid and invalid. could you please help me... (3 Replies)
Discussion started by: singhald
3 Replies

8. Shell Programming and Scripting

Extracting dynamic values

Hi, I am stuck with extracting values by combining 2 dynamically extracted values. The code goes like this #!/usr/bin/ksh ID1="abcd" i=1 #this is a dynamic value and keeps on changing b="ID" #this is static now i want the value of ID1 variable. like echo $b$i But echo... (1 Reply)
Discussion started by: chaitanyapn
1 Replies

9. UNIX Desktop Questions & Answers

Fetching unique values from file

After giving grep -A4 "feature 1," <file name> I have extracted the following text feature 1, subfeat 2, type 1, subtype 5, dump '30352f30312f323030392031313a33303a3337'H -- "05/01/2009 11:30:37" -- -- ... (1 Reply)
Discussion started by: shivi707
1 Replies

10. Shell Programming and Scripting

Extracting values from files

Im trying to create a utility that can do unit conversions using a seperate formula file(one which i can add conversions to at a later date). however i'm stuck when it comes to pulling the formulas out of the formula file for use in the script. heres a rundown of what the script does. The... (4 Replies)
Discussion started by: Master Error
4 Replies
Login or Register to Ask a Question