If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > sed -n using variable - white space !!!!!!

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-23-09, 10:07
mashy123 mashy123 is offline
Registered User
 
Join Date: Mar 2009
Posts: 5
sed -n using variable - white space !!!!!!

Hi,

wondering if anyone could help me, been racking my brain. am sure it's a simple one for the guru's amongst you......

I have used cat to get the line number from a file and wanted to list all between them lines. I used variables, however it seem like the second variable seems to have a few leading spaces. which sed -n does not like.

does anyone know how to avoid the extra spaces ???

Thanks for all your help in advance. Its the weekend so apoligies if I dont get back to anyone if I get any replies ;-)

thanks Raj


solaris 10

---script---
set -x
awk '{ print NR, $0}' ods_online.log > lines
all=`cat ods_online.log|wc -l`
mash=`cat lines |grep 2009|tail -1| awk {'print $1'}`
echo $mash
echo $all
cat ods_online.log |sed -n "'${mash},${all}p'"

--run output--

./m.sh
+ awk { print NR, $0} ods_online.log
+ 1> lines
+ + wc -l
+ cat ods_online.log
all= 100027
+ + cat lines
+ grep 2009
+ awk {print $1}
+ tail -1
mash=99340
+ echo 99340
99340
+ echo 100027
100027
+ sed -n '99340, 100027p'
+ cat ods_online.log
Unrecognized command: '99340, 100027p'
-----------------------------------------------

-------so its looks like it does not like the spaces-----------------
> cat ods_online.log|sed -n '99340, 100027p'
sed: command garbled: 99340, 100027p

-------manually removed spaces from command----works fine------
> cat ods_online.log|sed -n '99340,100027p'
Fri Oct 23 00:04:42 2009

00:04:42 Checkpoint Completed: duration was 0 seconds.
00:04:42 Fri Oct 23 - loguniq 122238, logpos 0x12719044, timestamp: 0x4dd9d335 Interval: 11014

00:04:42 Maximum server connections 97
00:04:42 Checkpoint Statistics - Avg. Txn Block Time 0.000, # Txns blocked 0, Plog used 2, Llog used 1
----------------------------------------------------------------
Reply With Quote
  #2 (permalink)  
Old 10-23-09, 10:34
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,517
Quote:
Originally Posted by mashy123
I have used cat to get the line number from a file and wanted to list all between them lines. I used variables, however it seem like the second variable seems to have a few leading spaces. which sed -n does not like.

does anyone know how to avoid the extra spaces ???
To be fair it's difficult working out what you want to do. If you just want to remove the leading spaces from a variable then can't you just use something like:
Code:
var=`echo $var | sed 's/^ *//'`
There may be a better way to write your program but I don't know what it is you're trying to do.
Reply With Quote
  #3 (permalink)  
Old 10-24-09, 10:38
kitaman kitaman is offline
Registered User
 
Join Date: Sep 2009
Location: Ontario
Posts: 526
Or:
all=`cat ods_online.log|wc -l`
all=`expr $all`
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On