deleting N lines of many files

Hi all,

I have about eighty directories,
called data-nn, where nn=00,01,02,....
in each of these directories I have
among others, an (ascii) data file with many thousends
lines. This data file has the same name in all
directories.

I would like to know if it is possible,
via a bash script, to delete the first N
lines in this data file in all directories.
The modified file can overwrite the old one.

Many thanks in advance,

Fabio Zyserman

-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo [at] vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Fabio Zyserman [ Fr, 17 Dezember 2004 13:33 ] [ ID #541221 ]

Re: deleting N lines of many files

Fabio Zyserman <zyserman [at] fcaglp.unlp.edu.ar> wrote:
> I have about eighty directories,
> called data-nn, where nn=00,01,02,....
> in each of these directories I have
> among others, an (ascii) data file with many thousends
> lines. This data file has the same name in all
> directories.
>
> I would like to know if it is possible,
> via a bash script, to delete the first N
> lines in this data file in all directories.
> The modified file can overwrite the old one.

Maybe you want something along the lines of (not tested!):

for i in `seq -w 0 80`; do sed -i "1,${N}d" $i/filename; done
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo [at] vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
zavandi [ Fr, 17 Dezember 2004 14:07 ] [ ID #541222 ]

Re: deleting N lines of many files

you can try this, in the parent directory of all these directories, type

find ./ -name "DATA_File_name" -exec sed "1,${N}d" {} > NEW_file_name \;

should be enough, you will have both new and old files, after
confirmation, you can move new ones to overwrite old ones.

Chen

On Fri, 17 Dec 2004, Fabio Zyserman wrote:

> Hi all,
>
> I have about eighty directories,
> called data-nn, where nn=00,01,02,....
> in each of these directories I have
> among others, an (ascii) data file with many thousends
> lines. This data file has the same name in all
> directories.
>
> I would like to know if it is possible,
> via a bash script, to delete the first N
> lines in this data file in all directories.
> The modified file can overwrite the old one.
>
> Many thanks in advance,
>
> Fabio Zyserman
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-admin" in
> the body of a message to majordomo [at] vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>


===========================================
Yu Chen
Howard Hughes Medical Institute
Chemistry Building, Rm 182
University of Maryland at Baltimore County
1000 Hilltop Circle
Baltimore, MD 21250

phone: (410)455-6347 (primary)
(410)455-2718 (secondary)
fax: (410)455-1174
email: chen [at] hhmi.umbc.edu
===========================================
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo [at] vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Yu Chen [ Fr, 17 Dezember 2004 15:01 ] [ ID #541223 ]

Re: deleting N lines of many files

At 12/17/2004 09:33 AM -0300, Fabio Zyserman wrote:
>I have about eighty directories, called data-nn, where nn=00,01,02,.... in
>each of these directories I have among others, an (ascii) data file with
>many thousends lines. This data file has the same name in all directories.
>
>I would like to know if it is possible, via a bash script, to delete the
>first N lines in this data file in all directories. The modified file can
>overwrite the old one.

Something like:

for file in data-[0-9][0-9]/filename
do
temp="${file}-temp"
tail +N "$file" > "$temp" && mv "$temp" "$file"
done

--
Jeff Woods <kazrak+kernel [at] cesmail.net>


-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo [at] vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Jeff Woods [ Fr, 17 Dezember 2004 21:01 ] [ ID #541355 ]
Linux » gmane.linux.admin » deleting N lines of many files

Vorheriges Thema: how to create tcl private headers
Nächstes Thema: samba or nfs?