Hello,
I'm using Windows 7 ; sed, awk and gnuwin32 are installed.
I have a big text file I need to manipulate.
In short, I will have to split it in thousands of short files, then rename and save in a folder which name is based upon filename.
Here is a snippet of my big input.txt file (this pattern is repeated 70k times) :
ctime=1041379201
version=text text
name=Bob.2111
targets=text text
title=text text
description=long text ending with[[#source_]]
As of now, I know how to split it with awk :
awk "/ctime/{x="F"++i;}{print > x;}" input.txt
Yet I dont know how to drive awk in renaming files.
In every splitted file, there is a line (line number 3 of the splitted file) which says the name of the expected file. In showed snippet, it is : name=Bob.2111
.
I expect to have about 70k files named like Bob.[0-9]+ (no extension).
My question number one is : is awk able to do that ? is awk able to catch a value in current file according to some pattern for renaming the splitted files ? I did not find anwser yet. Most examples order awk to use a name which doesnt come from the manipulated file.
My question number two is : is awk also able to save the splitted files in a constructed path, according to content ?
I want all splitted files containing Bob.1[0-9]+
to be saved in folder 1/ ; all Bob.2[0-9]+
to be saved in folder 2/, etc., for limiting the quantity of files per folder (using first number of numerical id).
I guess I need to catch every Bob.[0-9]+ in a variable $1.
Thus I may use this variable for (1) renaming files and (2) for moving files
If Bob.2111 is $1, I would like to save file like that {substring $1,4,20}/$1
which would give 2/Bob.2111
.
As you can guess, I'm not expert
Thank you.