Re: script question



2007-03-23, 14:04(-07), Mike:
From a script, I want to print all the lines of a file up to a line
containing the word "END".
Something like:

# grep -avw -m 1 "END" -f bla.txt

or

# cat bla.txt | while read line; do
echo $line
if [ "$line" == "END" ]; then break; fi
done


...except a script that actually works. The second one above does not
work because
the "read line" corrupts the lines by removing whitespace. I don't
know why the
first one doesn't work.
[...]

sed /END/q < bla.txt

Remember a shell is a command line interpreter, pick up the
command most suited for the job. Using a while read loop is the
most alien way to do shell programming.

--
Stéphane
.



Relevant Pages

  • Re: csccmd not running in script
    ... I moved the code around a little so that csccmd runs before anything else ... and I get no echo. ... command to complete so we can retrieve the return code. ... you may need to use "Run as Administrator" when you run the script. ...
    (microsoft.public.scripting.vbscript)
  • Re: Why no output display when I input at console
    ... echo running $e: ... There is no output on screen, which is not like that in script file ... After you think you fixed your PATH variable, look at it with the command ...
    (comp.unix.shell)
  • Re: Referencing Korn Shell Array Names as a Variable
    ... Your idea worked for displaying the output from the command. ... $ echo $ ... # Attempt to use variable array name and index to reference array value ... The issue is with this line of the script ...
    (comp.unix.shell)
  • Re: redirect for stdout in ${command_line}
    ... echo "Command line is shown below:" ... # END OF SCRIPT# ... I would accept a variable and build a command line while ... echo "Temp file contents are shown below:" ...
    (comp.unix.aix)
  • Re: Shell scripts: variable assignment within read loops
    ... things) to obtain information from a command, ... echo $foo ... echo "NICs: $nics" ... the script is to be used to gather ...
    (freebsd-questions)