Extract information into large variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extract information into large variable
# 8  
Old 10-27-2011
Ok jayan_jay, thanks Smilie
But I wanted to extract only one of those information, one specified by an very accurate delimiter for that I specified something who can only work with LevelName
You solution permit to extract all informations, by removing all other extra characters.
But you method is more friendly for me

Skrynesaver thanks too Smilie
You specified me a perfect command, but now I must include it into my script, and understand all your command since I'm not familiar with those type of perl input ^^'

Actually I used cut command, but that's not as accurate as I want, and my big variable change sometimes, so the number of delimiter I use may change and my cut command will be broked.

Here it's the code I'm using actually =>

Code:
echo ${bigvariable} >> /home/user/tempfile
cat /home/user/tempfile
levelName=$(cut -d '"' -f172 /home/user/tempfile)

So I will try to include Skrynesave's command into this portion of code =>

Code:
echo ${bigvariable} >> /home/user/tempfile
cat /home/user/tempfile
levelName=$(perl -e '@x=<>;$x=join "",@x;($l)=$x=~m/<add key="LevelName" value="(.+?)" type="System.String,mscorlib" \/>/;print "$l\n";' /home/user/tempfile)

By this way that's will work ?

jayan_jay, if you have something using awk, cut, grep or anything like that, who can replace the perl command, I will prefer that, since I will be probably more familiar to this method than the perl one.
# 9  
Old 10-27-2011
Code:
levelname=$(echo "${bigvariable}" | sed 's:.*<add key="LevelName" value="\([^"]*\)" type="System.String,mscorlib" />.*:\1:g')

This User Gave Thanks to CarloM For This Post:
# 10  
Old 10-27-2011
Quote:
Originally Posted by CarloM
Code:
levelname=$(echo "${bigvariable}" | sed 's:.*<add key="LevelName" value="\([^"]*\)" type="System.String,mscorlib" />.*:\1:g')

Oh Smilie
That's look like very fine CarloM
That's command will work with using flat file I presume ?
And the sed function remove all informations into the ${bigvariable} except the information I want that's right ?
# 11  
Old 10-27-2011
With the source (XML) in a flat file, or the output?
# 12  
Old 10-27-2011
Quote:
Originally Posted by CarloM
With the source (XML) in a flat file, or the output?
Ok I'm back and I did some test Smilie

So here it's the script I used to test that =>

Code:
bigvariable="<?xml version="1.0" encoding="utf-16" standalone="yes"?> <values> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="Log" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="Admin" value="true" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="LevelName" value="blabla" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="Fastdisk1" value="" type="System.String,mscorlib" /> <add key="Fastdisk2" value="" type="System.String,mscorlib" /> <add key="Fastdisk3" value="" type="System.String,mscorlib" /> <add key="backupinterval" value="300" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="true" type="System.String,mscorlib" /> <add key="backupeverything" value="false" type="System.String,mscorlib" /></values>"

levelname=$(echo "${bigvariable}" | sed 's:.*<add key="LevelName" value="\([^"]*\)" type="System.String,mscorlib" />.*:\1:g')
echo ${levelname} >> /home/+LOGS+/bla-test
cat /home/+LOGS+/bla-test

But actually there is something wrong, the output variable result by the full "bigvariable" :x

I think I have problem with the " used into bigvariable and I must to escape them or to do something ...

Last edited by WolwX; 10-27-2011 at 04:23 PM..
# 13  
Old 10-27-2011
Code:
perl -ne 'while(/value="(.*?)"/gi){print"$1\n" if(length$1>1)}' file.in > file.out

tip78
# 14  
Old 10-27-2011
Quote:
Originally Posted by tip78
Code:
perl -ne 'while(/value="(.*?)"/gi){print"$1\n" if(length$1>1)}' file.in > file.out

I'm sorry, I'm noob with that, can you explain me how include your command ?

Code:
bigvariable="<?xml version="1.0" encoding="utf-16" standalone="yes"?> <values> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="Log" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="Admin" value="true" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="LevelName" value="blabla" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="Fastdisk1" value="" type="System.String,mscorlib" /> <add key="Fastdisk2" value="" type="System.String,mscorlib" /> <add key="Fastdisk3" value="" type="System.String,mscorlib" /> <add key="backupinterval" value="300" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="" type="System.String,mscorlib" /> <add key="" value="true" type="System.String,mscorlib" /> <add key="backupeverything" value="false" type="System.String,mscorlib" /></values>"

levelname=$(echo "${bigvariable}" | sed 's:.*<add key="LevelName" value="\([^"]*\)" type="System.String,mscorlib" />.*:\1:g')
echo ${levelname} >> /home/+LOGS+/bla-test
cat /home/+LOGS+/bla-test

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to extract 8 characters from a large file.

Hi All!! I have a large file containing millions of records. My purpose is to extract 8 characters immediately from the given file. 222222222|ZRF|2008.pdf|2008|01/29/2009|001|B|C|C 222222222|ZRF|2009.pdf|2009|01/29/2010|001|B|C|C 222222222|ZRF|2010.pdf|2010|01/29/2011|001|B|C|C... (5 Replies)
Discussion started by: pavand
5 Replies

2. Shell Programming and Scripting

Extract information from file

In a particular directory, there can be 1000 files like below. filename is job901.ksh #!/bin/ksh cront -x << EOJ submit file=$PRODPATH/scripts/genReport.sh maxdelay=30 &node=xnode01 tname=job901 &pfile1=/prod/mldata/data/test1.dat ... (17 Replies)
Discussion started by: vedanta
17 Replies

3. Shell Programming and Scripting

Extract information from file

Gents, If is possible please help. I have a big file (example attached) which contends exactly same value in column, but from column 2 to 6 these values are diff. I will like to compile for all records all columns like the example attached in .csv format (output.rar ).. The last column in the... (11 Replies)
Discussion started by: jiam912
11 Replies

4. UNIX for Dummies Questions & Answers

Extract spread columns from large file

Dear all, I want to extract around 300 columns from a very large file with almost 2million columns. There are no headers, but I can find out which column numbers I want. I know I can extract with the function 'cut -f2' for example just the second column but how do I do this for such a large... (1 Reply)
Discussion started by: fndijk
1 Replies

5. Shell Programming and Scripting

How to extract specific information?

hi, i have a file A like this: ******************* No 2823 ******************** contig15205- G383C4U02H4G80+ is in contig15205- G383C4U02HGLXM- is in contig15205- G383C4U01C3HIZ+ is in contig15205- ... (3 Replies)
Discussion started by: the_simpsons
3 Replies

6. Shell Programming and Scripting

How to extract information from a file?

Hi, i have a file like this: <Iteration> <Iteration_iter-num>3</Iteration_iter-num> <Iteration_query-ID>lcl|3_0</Iteration_query-ID> <Iteration_query-def>G383C4U01EQA0A length=197</Iteration_query-def> <Iteration_query-len>197</Iteration_query-len> ... (9 Replies)
Discussion started by: the_simpsons
9 Replies

7. Shell Programming and Scripting

Extract data from large file 80+ million records

Hello, I have got one file with more than 120+ million records(35 GB in size). I have to extract some relevant data from file based on some parameter and generate other output file. What will be the besat and fastest way to extract the ne file. sample file format :--... (2 Replies)
Discussion started by: learner16s
2 Replies

8. Shell Programming and Scripting

Extract large list of substrings

I have a very long string (millions of characters). I have a file with start location and length that is thousands of rows long: Start Length 5 10 16 21 44 100 215 37 ... I'd like to extract the substring that corresponds to the start and length from each row of the list: I tried... (7 Replies)
Discussion started by: dcfargo
7 Replies

9. Shell Programming and Scripting

AWK to extract information

Hi all, I am working on a shell script to extract information from a file that has output from Oracle sqlplus. The problem is that the output of a single line is spread across multiple lines and i do not know as how to extract the particular filed at ones,which spans multiple lines.... (2 Replies)
Discussion started by: harris2107
2 Replies

10. Shell Programming and Scripting

How do you extract the information from a library?

hi all, i am quite new with Perl (just 1 week of experience) and i am suppose to understand the usage of library, which i can't, anyway... i came across this library...i think from the linux redhat redhat.linux.lib.pl, there are a couple of functions there that can be used to retrieve information... (3 Replies)
Discussion started by: mercz
3 Replies
Login or Register to Ask a Question