Filtering leading spaces from text string.
Posted on 2000-03-02
I need a quick fix and am experiencing brain fade so I thought I would offer you nice people a chance at some easy point, It's been a while since I posted a question so I thought it would be fun.
OK here ya go ... shouldnt be too tough.
Nightly we dump logs of our database and filesystem backups to a text "log" file. for one field entry we tail the "fixed" output file from Informix and pipe it through "head -1" to grab just the first line. So far this has worked fine but now I am formatting (mostly cleaning up) the format to be place in a database for query level reporting.
So...we have one line of text in one file, unfortunately this text has LEADING spaces that I would like to eliminate, theres your question.
How do I filter a line that looks something like " 143121 - 143856" into something like "143121 - 143856" ?
A couple things... first notice that there MAY be additional spaces embedded in the string before and after the "-" these can be left in place or filtered out, I dont care, what I do care about is that the actual text value (Database logical log numbers) stay in tact an accurate. ALSO the solution should be shell independent as we may use C shell on one system and K shell or Bourne shell on others. Thinking maybe AWK or SED or even a GREP statement might do it ???
Current syntax (if it helps) is:
(filename is an example)
LOGS="'tail -3 /testfile.flg | head -1 '"
if [ -f "/testfile.log" ]
ORIGNUM= 'head -1 "/testfile.log'
ORIGNUM1='expr $ORIGNUM -1'
then this string gets echoed out to sendmail and to a logfile.
Its a little rough, since you dont have all the varible info but I think you see the drift.
I put the value at 100 cuz I feel like giving away points , sound fair ?