Script to cut the first word in Message Text


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to cut the first word in Message Text
# 1  
Old 07-15-2009
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.

Code:
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

Code:
"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

Last edited by radoulov; 07-15-2009 at 07:15 AM..
# 2  
Old 07-15-2009
Lot of solution, here is simple solution for posix-sh, ksh, bash, ...:
Code:
MESSAGE_TEXT=${MESSAGE_TEXT%% *}

table output, what is input format, some lines example ?
# 3  
Old 07-15-2009
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:
Code:
awk 'NR>1{exit} {print $1}' file

For String:
Code:
echo "sample string" | awk '{print $1}'

# 4  
Old 07-15-2009
Quote:
Originally Posted by balajiora
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
[...]
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 [code] and [/code] 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:

Code:
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`

Quote:
2. Is there any way, I can format the results (HTML Table Format)
Yes,
just add:

Code:
set markup html on

# 5  
Old 07-15-2009
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
Quote:
Originally Posted by balajiora
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[/quote]
# 6  
Old 07-15-2009
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.
# 7  
Old 07-15-2009
somecmd | ./htmloutput cgi
or
somecmd | ./htmloutput > some.html

Code:
#!/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

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reading a word from a text file into shell script

Hi, I am new to shell programming.I need to write a script that would accept a word from each line fo an input text file.Can anyone help me with this?Exact requirement: word1 word2 word3 (separated by space) .Now I need word3 from each such line in the text file. Thanks in Advance, Manish (3 Replies)
Discussion started by: manish007
3 Replies

2. UNIX for Dummies Questions & Answers

Script to add text before the first word on a line in a textfile.

How can i make a script to add text before the first word on a line in a textfile : Example: Old line: is my place New line: this is my place Please use and tags when posting code, data or logs etc. to preserve formatting and enhance readability, thanks. (3 Replies)
Discussion started by: mjanssen
3 Replies

3. UNIX for Dummies Questions & Answers

BASH script that sends text message or email

Hi, I have a BASH shell script that batch processes data. I often start this script before I leave to go home for the day, and leave it processing over night. It has come to my attention that it would be very useful for me to add the capability of making the script notify me about certain things... (2 Replies)
Discussion started by: msb65
2 Replies

4. Shell Programming and Scripting

Help need to cut the first word of a line in text file

Hi All, I would like help with a script which can get rid of the first work of all lines in text file. File 1 The name is Scott. Output : name is Scott ---------- Post updated at 02:38 PM ---------- Previous update was at 02:37 PM ---------- Hi ALL There is typo error in... (3 Replies)
Discussion started by: bubbly
3 Replies

5. Shell Programming and Scripting

How to cut first line only from a text near a specific column without cutting a word

First I have to say thank you to this community and this forum. You helped me very much builing several useful scripts. Now, I can't get a solution the following problem, I'm stuck somehow. Maybe someone has an idea. In short, I dump a site via lynx and pipe the output in a file. I need to... (7 Replies)
Discussion started by: lowmaster
7 Replies

6. Shell Programming and Scripting

script to cut a word from the file

hi to all i wrote a script to cut a word from the file....that works only if the word is fixed field. example.. sed -n '1p'|awk '{ print $2 }'|cut -d '(' -f2|sed 's/(//'|sed 's/)//'|sed 's/"//g' filename i know that word is starting with "app" then "(" ----> ex: app("xxxx"). it... (2 Replies)
Discussion started by: honeym210
2 Replies

7. UNIX for Advanced & Expert Users

Mutt - Word Document or Formatted text as a Message

Hi, I am writing a mailing script by using mutt command. I that i have facing a issues. because, i want to send Some Formatted text as the mail message. but, i try to send the Word Document file as the Mail message. it shows some junk characters in the mail. :confused:I think the mutt command is... (1 Reply)
Discussion started by: krsenkumar
1 Replies

8. Shell Programming and Scripting

blink a text/message in a ksh script

can anyone tell me how to bink a text in a ksh script for e,g file 1 #!/bin/ksh "this is my file" ----------------------------------------------- i want "this is my file" text to blink.thanks (9 Replies)
Discussion started by: ali560045
9 Replies

9. Shell Programming and Scripting

Can a shell script pull the first word (or nth word) off each line of a text file?

Greetings. I am struggling with a shell script to make my life simpler, with a number of practical ways in which it could be used. I want to take a standard text file, and pull the 'n'th word from each line such as the first word from a text file. I'm struggling to see how each line can be... (5 Replies)
Discussion started by: tricky
5 Replies
Login or Register to Ask a Question