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

    Supernoob: Help me Remove Intermediate Files

    Hello again. Thanks to the folks who helped me work out the parameter problem!

    However, since I'm not 100% on how output is piped into STDIN as opposed to text files, I'm getting some weirdness when attempting to replace the "temp" file below with a variable/pipe:

    tr ' ' x < $filename | sed 's/$/\n/' > temp
    supnums=`grep 'X-\|X$' temp | sed 's/,5,.*$//'`
        for sups in $supnums
                grep "^$sups,4" temp | sed 's/.*4,//'
    I've tried assigning the output of line 5 to a variable called "nospaces", then grepping the cat of $nospaces, but the ` symbol is making the output of the cat | grep execute as a command. Consequently I get a bunch of annoying "command not found" lines as output.

    O great and powerful penguins, can you help me on this quest?

  2. #2
    I suppose I wasn't being very clear. This is my attempt to remove the file "temp" from the script, by replacing it with a variable, $nospaces:

    nospaces=`tr ' ' x < $filename | sed 's/$/\n/'`
    supnums=`echo $nospaces | grep 'X-\|X$' | sed 's/,5,.*$//'`
        for sups in $supnums
                echo $nospaces | grep "^$sups,4" | sed 's/.*4,//'
    Unfortunately I get no output whatsoever, though given the time it took to run, I know the loop was working. That's what I meant by the 'weirdness' -- output direction into files makes newlines where I expect them, but the newlines seem to disappear when I assign the output to variables. Anyone know what I mean? Is there a cure for this that doesn't involve making a temp file?

  3. #3
    Linux Engineer
    Join Date
    Apr 2012
    Virginia, USA
    Here is the line you need to change:

    nospaces=$(tr ' ' x < $filename | sed 's/$/\n/')

  4. $spacer_open
  5. #4
    I'm afraid that didn't work -- all the newlines are still being removed when I call $nospaces. Maybe it's got something to do with my build?


    I've decided to alter the regexp I was using for the program -- which I can do now that I've learned the basics of AWK. So I don't care if the variable preserves lines anymore. Thanks anyway
    Last edited by deuteros; 02-23-2013 at 11:38 PM.

Posting Permissions

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