Home » Infrastructure » Unix » Search word between two strings (Sun OS sun4u Sparc SUNW)
Search word between two strings [message #442998] Thu, 11 February 2010 23:22 Go to next message
Messages: 87
Registered: September 2005
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.


[Updated on: Thu, 11 February 2010 23:23]

Report message to a moderator

Re: Search word between two strings [message #442999 is a reply to message #442998] Thu, 11 February 2010 23:38 Go to previous messageGo to next message
Michel Cadot
Messages: 67946
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
1/ This is not an Oracle question
2/ Post what you tried.

Re: Search word between two strings [message #445429 is a reply to message #442998] Mon, 01 March 2010 16:58 Go to previous message
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)


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.
Previous Topic: Procedure with input/output params called in Unix
Next Topic: copy file from unix system to sharepoint
Goto Forum:

Current Time: Mon Sep 20 12:11:03 CDT 2021