Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2009
    Posts
    5

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

  2. #2
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    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.

  3. #3
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    Or:
    all=`cat ods_online.log|wc -l`
    all=`expr $all`

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •