Help with extracting text from a string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with extracting text from a string
# 8  
Old 02-25-2010
Question What Operating System

Are you using bash, or ksh, or ???
# 9  
Old 02-25-2010
i am using bash.

Thanks.
# 10  
Old 02-25-2010
Tools

Does this
Code:
$ echo test=A /content/qa/lesson1/index.html A /content/qa/lesson2/index.html | gawk '{print $2"\n"$4}'

give you
Code:
/content/qa/lesson1/index.html
/content/qa/lesson2/index.html

# 11  
Old 02-25-2010
thanks joeyg.

yes that works. but when i added that grep part on my hookscript, i am getting nothing. just the echo works fine as you said.

here is a part of my hook script.

Code:
changes=`/usr/bin/svnlook changed $REPOS -r $REV | grep "^A.*index.html$" | gwak 'print $2"\n"$4}'`
echo '>>>'$changes >> $ACTION_LOG

So what i am doing here is checking to see if new index.html file has been added to the repository. and then from there i am need to extract the folder name.

Code:
changes=`/usr/bin/svnlook changed $REPOS -r $REV | grep "^A.*index.html$"`

gives you the
Code:
A  /content/qa/lession1/index.html A /content/qa/lession2/index.html

so i added the script you gave me to it.
Code:
changes=`/usr/bin/svnlook changed $REPOS -r $REV | grep "^A.*index.html$"| gwak 'print $2"\n"$4}'

didnt give me anything back.

Last edited by Scott; 02-25-2010 at 06:26 PM.. Reason: Code tags
# 12  
Old 02-25-2010
Tools Other ways to accomplish, but keeping with your flow...

After you set the variable changes
Code:
>echo "$changes"

to see it on the screen
then, you might want
Code:
echo ">>>$changes" >> $ACTION_LOG

as sometimes spaces and other characters can confuse things
# 13  
Old 02-25-2010
yes it didnt work either. I get resonse printed on the log file for the previous command
Code:
changes=`/usr/bin/svnlook changed $REPOS -r $REV | grep "^A.*index.html$"`
echo '>>>'$changes >> $ACTION_LOG

as
Code:
>>>A /content/qa/lession1/index.html A /content/qa/lession2/index.html

thanks.

---------- Post updated at 05:14 PM ---------- Previous update was at 04:43 PM ----------

One thing I also realised that gawk '{print $2"\n"$4}' works only if you have two files. if it is more than 2 then index. If there are three files checked in to the repository it will still return only 2 files.
Code:
$  echo test=A /content/qa/lesson1/index.html A /content/qa/lesson2/index.html A /content/qa/lesson3/index.html| gawk '{print $2"\n"$4}'
/content/qa/lesson1/index.html
/content/qa/lesson2/index.html

this is not what i am looking for.

Last edited by Scott; 02-25-2010 at 06:27 PM.. Reason: Code tags
# 14  
Old 02-25-2010
Can you just enter the command?
The way you have it, you are writing output from the command to a string and then writing that to a file. Thus, why do you need to write the >>> ?
Do this
Code:
changes=`/usr/bin/svnlook changed $REPOS -r $REV | grep "^A.*index.html$"`
echo '>>>'$changes >> $ACTION_LOG
/usr/bin/svnlook changed $REPOS -r $REV | grep "^A.*index.html$" | gawk '{print $2"\n"$4}

which should write your stuff, but also execute the same command and send new output to the screen
Code:
/content/qa/lesson1/index.html
/content/qa/lesson2/index.html

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extracting substring within string between 2 token within the string

Hello. First best wishes for everybody. here is the input file ("$INPUT1") contents : BASH_FUNC_message_begin_script%%=() { local -a L_ARRAY; BASH_FUNC_message_debug%%=() { local -a L_ARRAY; BASH_FUNC_message_end_script%%=() { local -a L_ARRAY; BASH_FUNC_message_error%%=() { local... (3 Replies)
Discussion started by: jcdole
3 Replies

2. UNIX for Dummies Questions & Answers

Extracting lines from a text file based on another text file with line numbers

Hi, I am trying to extract lines from a text file given a text file containing line numbers to be extracted from the first file. How do I go about doing this? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

3. Shell Programming and Scripting

Extracting text from within a section of text using AWK

I have a command which returns the below output. How can I write a script to extract mainhost and secondhost from this output and put it into an array? I may sometimes have more hosts like thirdhost. I am redirecting this output to a variable. So I guess there should be a awk or sed command to... (7 Replies)
Discussion started by: heykiran
7 Replies

4. Shell Programming and Scripting

Extracting several lines of text after a unique string

I'm attempting to write a script to identify users who have sudo access on a server. I only want to extract the ID's of the sudo users after a unique line of text. The list of sudo users goes to the EOF so I only need the script to start after the unique line of text. I already have a script to... (1 Reply)
Discussion started by: bouncer
1 Replies

5. Shell Programming and Scripting

Extracting particular string in a file and storing matched string in output file

Hi , I have input file and i want to extract below strings <msisdn xmlns="">0492001956</ msisdn> => numaber inside brackets <resCode>3000</resCode> => 3000 needs to be extracted <resMessage>Request time getBalances_PSM.c(37): d out</resMessage></ns2:getBalancesResponse> => the word... (14 Replies)
Discussion started by: sushmab82
14 Replies

6. Shell Programming and Scripting

Extracting String

I am trying to extract a hyperlink from a html document using awk. I have managed to output in the format... href="index.html"> where i would like it just to output index.html. Any ideas on how i would do this? Thanks (2 Replies)
Discussion started by: adpe
2 Replies

7. UNIX for Dummies Questions & Answers

extracting text and reusing the text to rename file

Hi, I have some ps files where I want to ectract/copy a certain number from and use that number to rename the ps file. eg: 'file.ps' contains following text: 14 (09 01 932688 0)t the text can be variable, the only fixed element is the '14 ('. The problem is that the fixed element can appear... (7 Replies)
Discussion started by: JohnDS
7 Replies

8. Shell Programming and Scripting

extracting a string

Hi All, I am writing a shell script for which I am stuck with an extraction part. I arrived till extraction of a path of file. Lets take an example. I now have a file which contains following one line: 2348/home/userid/mydir/any_num_dir/myfile.text Now I want to extract only... (2 Replies)
Discussion started by: start_shell
2 Replies

9. Shell Programming and Scripting

Extracting a string from one file and searching the same string in other files

Hi, Need to extract a string from one file and search the same in other files. Ex: I have file1 of hundred lines with no delimiters not even space. I have 3 more files. I should get 1 to 10 characters say substring from each line of file1 and search that string in rest of the files and get... (1 Reply)
Discussion started by: mohancrr
1 Replies

10. Shell Programming and Scripting

extracting from a string

How do I extract 5th to 10th characters of string as given below stored in a shell variable. "ab cd ef gh ij kl" How is cut to be used on this? Thanks for any help. (1 Reply)
Discussion started by: preetikate
1 Replies
Login or Register to Ask a Question