Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unix .sh script stripping line feeds from grep

Status
Not open for further replies.

dreamaz

Technical User
Dec 18, 2002
184
0
0
CA
Hello,

I have a .sh script that grep's a text file, when the result is returned, its all mixed in together in one line:
07/25/2007,20:40:42,jubileeNT,Start,9999999999@mb.next.co.ke,200,9999999999@mb.next.co.ke,199.251.23.76,35406,199.21532.161,000009999999999,server-03-PCSCLN03,1,,,,,,,,,,,1185396042,,416565070091,16H9zrig,16H9z2JF,59,,, 07/25/2007,20:40:43,jubileeNT,Stop,9999999999@mb.next.co.ke,200,9999999999@mb.next.co.ke,199.251.23.76,35406,199.21532.161,000009999999999,server-03-PCSCLN03,2,0,0,0,1,,,,,,,1185396043,,416565070091,16H9zrig,16H9z2JF,59,0,0,

When i run the script manually, it looks fine, it may look the same when i pasted it below, but actually the each date stamp is on a new line, whereas in teh above its all together
07/25/2007,20:40:42,jubileeNT,Start,9999999999@mb.next.co.ke,200,9999999999@mb.next.co.ke,199.251.23.76,35406,199.21532.161,000009999999999,server-03-PCSCLN03,1,,,,,,,,,,,1185396042,,416565070091,16H9zrig,16H9z2JF,59,,,
07/25/2007,20:40:43,jubileeNT,Stop,9999999999@mb.next.co.ke,200,9999999999@mb.next.co.ke,199.251.23.76,35406,199.21532.161,000009999999999,server-03-PCSCLN03,2,0,0,0,1,,,,,,,1185396043,,416565070091,16H9zrig,16H9z2JF,59,0,0,

Does anyone have any ideas, please see script below:

#!/bin/sh
clear
echo ""
echo "Command Usage: ./y.sh <MIN> <yyyymmdd>"
echo "Please Select An Option"
echo ""
echo "1) for Eastern - Auth"
echo "2) for Eastern - Acct"
echo "3) for Western - Auth"
echo "4) for Western - Acct"
echo ""
echo "Select: \c"
read ans
case $ans in
'1')
echo `/usr/bin/zcat /elog/pcs1/app/$2*.log.Z | grep $1`
echo `/usr/bin/zcat /elog/pcs2/app/$2*.log.Z | grep $1`
;;
'2')
echo `grep $1 /elog/pcs1/app/$2.act`
echo `grep $1 /elog/pcs2/app/$2.act`
;;
'3')
echo `grep $1 /wlog/pcs1/app/$2*.log`
echo `grep $1 /wlog/pcs2/app/$2*.log`
;;
'4')
echo `grep $1 /wlog/pcs1/app/$2.act`
echo `grep $1 /wlog/pcs2/app/$2.act`
;;
*)
echo "Searching for:" $S_FILTER
esac

Thanks,

dR
 
Replace all echo `stuff here` with echo [!]"[/!]`stuff here`[!]"[/!]

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Or simply leave out the echos and the backquotes...

Code:
...
case $ans in
'1')
       /usr/bin/zcat /elog/pcs1/app/$2*.log.Z | grep $1
       /usr/bin/zcat /elog/pcs2/app/$2*.log.Z | grep $1
       ;;
'2')
       grep $1 /elog/pcs1/app/$2.act
       grep $1 /elog/pcs2/app/$2.act
       ;;
'3')
       grep $1 /wlog/pcs1/app/$2*.log
       grep $1 /wlog/pcs2/app/$2*.log
       ;;
...


HTH,

p5wizard
 
Thanks,

How can i encrypt/compile this so that people cant CAT my .sh file?

I see some other scripts on our system with a .sh.x and when i cat it its all encrypted

Any ideas?

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top