Here is how you assign output to a variable.
If you post the input and how you like the output would be, it would be more easy to give you a correct guide.
Narrative: If you find a line with '<PORT>', optional spaces, some not-space-value, optional spaces and '</port>', turn the entire line into the not-space-value and print it. The * is greedy, so the ' * after <port> will stop just before the first not space value, and we must stop the captured \(...\) value before we scoop up any spaces, so it must end in a non-space; the .* before that is ensured to start with a not space by the greedy prior ' *' -- left greedy beats right greedy. Not that I ensure anything on the line before and after is picked up and not laid back down. We could still be fooled by '<port> 1 2 </port>', but we are assuming that the data is 'well behaved' with one port on any line. If it was really well behaved, there would be no spaces in there. Maybe they were before or after it all, not inside. Never give a white space your trust, it could be spaces, backspaces, tabs, carriage returns, form feeds, iso8859-1 nonbreaking spaces (space + 128), and other control characters that leave no glyph. In ascii, there is [!-~] that you can see, and then there is the rest.
Last edited by DGPickett; 03-12-2013 at 04:39 PM..
Reason: I only wanted one space there. Two spaces is for speed in other space chasers.
I tried the code but nothing was returned. No error. No output.
Quote:
Originally Posted by DGPickett
Narrative: If you find a line with '<PORT>', optional spaces, some not space value, optional spaces and '</port>', turn the entire line into the not space value and print it.
---------- Post updated at 03:31 PM ---------- Previous update was at 03:28 PM ----------
Tried with a single space after the <port> and it worked. Spaces trimmed and output assigned. Thanks much!
Quote:
Originally Posted by DGPickett
Narrative: If you find a line with '<PORT>', optional spaces, some not space value, optional spaces and '</port>', turn the entire line into the not space value and print it.
Hi
iam new to shell scripting
how to declare variables as redshift query and I have to compare two counts by using if condition .
ex:count=select count(*) from prd;
select count(*) from prd;
select count(*) from tag;
can any one help me .
Please use CODE tags when displaying... (1 Reply)
Hi Folks,
I am trying to assign a value from the command to a dynamic variable. But I am not getting the desired output.. I am sure something is wrong so i need experts advise.
There will be multiple files like /var/tmp/server_1, /var/tmp/server_2, /var/tmp/server_3, having different server... (6 Replies)
Code
set -x
STATUS="0"
echo $STATUS
for i in `ls -ltr Report*|awk '{ print $9 }'`
do
if
then
flg = "`head -1 "$i" |cut -c 31-33`"
echo `head -1 "$i" |cut -c 31-33`
echo $flg
if
then
echo "having Fun"
STATUS="2"
else
echo "no Fun"
fi
fi (2 Replies)
Greetings folks,
I am trying to assign the output of a dscl command (contains name<spaces>id) to a variable as an array. Currently I am piping the output into a tmp file, then reading the tmp file into an array, then parsing the array. I would like to bypass creating the tmp file portion of... (6 Replies)
Hi ,
I would like to assign command (with pipe) output to a variable. The code is as follows. The goal of the code is to get the last folder folder with a particular name pattern.
myDate=`ls | grep 2009 | tail -1`
echo "myDate=" $myDate
However, in the presence of the pipe, the code... (3 Replies)
Hi All
I have a file for ex .log file which contain several lines within it.
I have to read that file contents & assing that to a variable. (2 Replies)
Hi Team,
I need to get data from oracle table & need to assign that value to unix variable. I have serched the same in other threads. I found the following code.
I have tried code to get the value from oracle. but it is not working. The error shows invalid identifier "NAM" & then list all... (5 Replies)
Hi,
I am giving a grep command, and i am getting the output. i want to store it in a variable
for eg
a = grep '12345' /dir/1/2/log.txt ( the output is number)
b= grep 'basic' /dir/1/2/log1.txt (in this case the output is character)
so how to assign the output of grep to a variable
... (1 Reply)
Hi ,
I have a code like this:
uid=scott
password=tiger
database=db01
cat >runid_val.sql<<-EOA
SET ECHO OFF
SET FEEDBACK OFF
SET HEADING OFF
SELECT trim(runid_seq.nextval) FROM dual;
EXIT
EOA
echo `cat runid_val.sql`
V_RUNID=`sqlplus -s $uid/$password@$database @runid_val.sql`... (5 Replies)