Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Removing Space in File

    I'm reading in a file with various table names, creating SQL to find a count of all the records in the table, then outputting both the table name and the record count to a file.

    The output file has the table name, a space, then the record count.

    I do not want that space there, but for the life of me, I can't figure out how to make it go away. I'd prefer to have a delimiter like a comma or anything else.

    Here's my wee code to read the input file and create the output file (TableCount is another script that does the counting):

    while read line
      RECORDCOUNT=`TableCount $var1 $var2 $var3 $line`
      echo "$line$RECORDCOUNT" >> $TABLECOUNTS
    done < $TABLELIST
    Perhaps the space that I see in the file, isn't really a space... what I've been doing is reading in that file, trying to strip out the space using sed, and writing it to another file just to see what I get. But sed doesn't want to strip out that space.

    while read line2
      echo $line2 | sed 's/  */\|/g' >> $TABLECOUNTS2
    done < $TABLECOUNTS
    Seems simple... but I really am a scripting newbie, I don't know sed at all, so I'm going on examples I'm finding on the web. I keep getting a space between the table name and the record count.

    Can anyone help? When I load the output file into a Sybase table, and I do a select on it, I don't get the table name properly because it's putting the trailing space into the table. Or so it seems, anyway. I might see if I can just not take that space on the table load... but I wanted to try this first.


  2. #2
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Seattle, WA, USA
    In the segment you posted here, it looks like there is no space, but some sort of newline instead.

    Fortunately, it's relatively easy to find out what character you actually have there by using the "od" command. Try the -a and -c flags.

Posting Permissions

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