Results 1 to 4 of 4
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 02-19-2013 #1Just Joined!
- Join Date
- Feb 2013
- Posts
- 19
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:
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.Code:#!/bin/bash filename=$1 tr ' ' x < $filename | sed 's/$/\n/' > temp supnums=`grep 'X-\|X$' temp | sed 's/,5,.*$//'` for sups in $supnums do grep "^$sups,4" temp | sed 's/.*4,//' done
O great and powerful penguins, can you help me on this quest?
- 02-19-2013 #2Just Joined!
- Join Date
- Feb 2013
- Posts
- 19
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:
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?Code:#!/bin/bash filename=$1 nospaces=`tr ' ' x < $filename | sed 's/$/\n/'` supnums=`echo $nospaces | grep 'X-\|X$' | sed 's/,5,.*$//'` for sups in $supnums do echo $nospaces | grep "^$sups,4" | sed 's/.*4,//' done
- 02-20-2013 #3Linux Enthusiast
- Join Date
- Apr 2012
- Location
- Virginia, USA
- Posts
- 561
Here is the line you need to change:
nospaces=$(tr ' ' x < $filename | sed 's/$/\n/')
- 02-23-2013 #4Just Joined!
- Join Date
- Feb 2013
- Posts
- 19
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?
EDIT:
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 10:38 PM.


Reply With Quote
