Not with split
, but you can easily rename them afterwards, or you can do it in awk
:
awk '{filename = "wrd." int((NR-1)/10000) ".txt"; print >> filename}' inputfile
Might be as simple as
cp file.{ext,bak.ext}
bash {} expansion expands to all combinations (unlike [] expantion which lists existing files. So it generates two file names.
The { .... , .... }
provides two options, so you get
file.ext and file.bak.ext
In your script you would use
cp $FILE.{$EXTENTION,bak.$EXTENTION}
And to break up the FILENAME into the two halves you can use
FILE=${FILENAME%.*}
EXTN=${FILENAME##*.}
${VAR%xxxxx} will return the left side of what is in VAR up to the matching pattern, in the case above the pattern is .* so you get everything except the last .*
${VAR##xxxxx} will return the right side of what is in VAR, after the matching pattern. The double hash means get the biggest possible match, in case there is more than one possble match.
To make your script save, check for cases where after obtaining FILE and EXTENTION, that they are not the same thing. This will happen in cases where the file name doesn't have an extention.
A sub-section of your script might look like this:
ls *html | while read FILENAME
do
FILE=${FILENAME%.*}
EXTN=${FILENAME##$FILE}
cp $FILE{$EXTN,.bak$EXTN}
done
Best Answer
You can easily do this with a shell loop in
bash
:Once you are satisfied that does what you need, remove the echo to actually rename the files:
The
-i
will makemv
ask before overwriting if one of the new names already exists.