Search word between two strings [message #442998] |
Thu, 11 February 2010 23:22 |
mchittib
Messages: 87 Registered: September 2005
|
Member |
|
|
I have a string returned from the ftp site and it is
Connected to server. .................................150 Opening ASCII mode data connection for /bin/ls. 8 226 Listing Completed. local: |wc -l .............................
How can I find the string between data connection for /bin/ls. and 226 Listing Completed.
Output I needed is 8.
It changes by the number of files I have on ftp site.
I tried grep and awk but it is returning the whole string.
Please help.
Thanks.
[Updated on: Thu, 11 February 2010 23:23] Report message to a moderator
|
|
|
|
Re: Search word between two strings [message #445429 is a reply to message #442998] |
Mon, 01 March 2010 16:58 |
andrew again
Messages: 2577 Registered: March 2000
|
Senior Member |
|
|
-- get the subtring starting /bin/ls to the end of the line
-- print the second field (the one you want)
-- read into some shell variable (play it safe and catch any junk into second var)
#/usr/bin/ksh
echo "Connected to server. ...150 Opening ... for /bin/ls. 8 226 Listing Completed..." | \
awk '{ $0=substr($0, index($0,"/bin/ls")); print $2}' | read X junk
echo "Result is $X"
You need to do some sanity check on the output before trying to isolate the result. Determine what strings in the output indicate failre vs success.
|
|
|