Script to cut the first word in Message Text

Hi,

In my shell script, I am connecting to database and querying multiple columns in a table.

MESSAGE_TEXT=`sqlplus -s /nolog <<end_log_stmt
set heading off
set feedback off
set verify off
set termout off
set pages 0

CONNECT APPS/$USER_PWD
    Select order_number, id, error_message from table some condition to get 1 row;
end_log_stmt`

While printing the MESSAGE_TEXT, I am getting the value as

"Connected. 1000301, 23343, Sample Error message. some time with full stop"

I have tried using cut command to cut the "Connected" string keeping full stop as delimiter. This is working if there is no full stop in error message.

  1. Can anyone help me giving the script to cut the first word in message text.
  2. Is there any way, I can format the results (HTML Table Format)

Thanks in advance.

Regards
BS

Lot of solution, here is simple solution for posix-sh, ksh, bash, ...:

MESSAGE_TEXT=${MESSAGE_TEXT%% *}

table output, what is input format, some lines example ?

Can you post sample input and the expected output? Please use code tags to improve the readability.

However, here are some things you can give a try -

For File:

awk 'NR>1{exit} {print $1}' file

For String:

echo "sample string" | awk '{print $1}' 

To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags

```text
 and 
```

by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums

Back to your question: just change the code like this:

MESSAGE_TEXT=`sqlplus -s <<end_log_stmt
APPS/$USER_PWD
set heading off
set feedback off
set verify off
set termout off
set pages 0

Select order_number, id, error_message from table some condition to get 1 row;
end_log_stmt`

Yes,
just add:

set markup html on

Thanks for your prompt reply...

Above query I am going to execute in a loop. Assume that I am getting five lines of records

1000301, 23343, Sample Error message. some time with full stop
1000302, 23343, Sample Error message
1000303, 23343, Sample Error message
1000304, 23343, Sample Error message

I need to format this.

Regards
BS

---------- Post updated at 04:13 PM ---------- Previous update was at 04:11 PM ----------

Thanks for your prompt reply...

Above query I am going to execute in a loop. Assume that I am getting five lines of records

I need to format this.

Regards
BS
[/quote]

In a loop where? In the database via PL/SQL or outside via shell script?
I would suggest using one database connection to get and format all data/output.

somecmd | ./htmloutput cgi
or
somecmd | ./htmloutput > some.html

#!/bin/ksh
#htmloutput
linetemplate()
{
cat <<EOF
<tr><td>$1</td><td>$2</td><td>$3</td></tr>
EOF
}

###MAIN###
header=""
[ "$1" = "cgi" ] && header="Content-type: text/html"
cat <<EOF
$header

<html>
<body>
<table>
EOF

oifs="$IFS"
while read line
do
     IFS=","
     linetemplate $line
     IFS="$oifs"
done

cat <<EOF
</table>
</body>
</html>
EOF