[Gambas-user] bash question
Doriano Blengino
doriano.blengino at ...1909...
Thu Oct 8 09:15:20 CEST 2009
richard terry ha scritto:
> to any scripters amongst us.
>
> is there any simple bash command to remove the first line in a file and leave
> the rest?, short of reading all the lines and re-writing the file?
>
tail -n+2 your_file_name
will output to standard output the file indicated, starting from the
second line (ie, omitting the first one). It is important the plus sign,
otherwise you will get the 'n' (n=2 in this example) last lines instead.
You can redirect the standard output somewhere else (another file). You
can not redirect to the same file, so you need two stages with a
temporary file to hold the result:
tail -n+2 your_file_name > /tmp/temporary_file; mv
/tmp/temporary_file your_file_name
In the previous double command the file /tmp/xxx is chosen arbitrarily,
but probably it suffices; otherwise take a look at mktemp(1); it can be
used like this:
tmp=$(mktemp); tail -n+2 your_file_name > $tmp; mv $tmp
your_file_name
The above line is formed by three commands, and can be passed to a SHELL
in gambas.
Btw, also "sed" and "awk" instead of "tail" can do this, and even much
more, but they are heavier.
Regards,
Doriano
More information about the User
mailing list