Sponsored Content
Top Forums Shell Programming and Scripting awk : split file and rename and save in path according to content Post 302937660 by sellig on Saturday 7th of March 2015 10:59:01 AM
Old 03-07-2015
awk : split file and rename and save in path according to content

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) :
Code:
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 :
Code:
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 Smilie
Thank you.

Last edited by sellig; 03-07-2015 at 01:18 PM.. Reason: typo
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

split file depending on content

Hi, I have a file which contains records of data. I need to split the file into multiple files depending upon the value of last field. How do i read the last field of each record in the file??? Regards, Chaitrali (4 Replies)
Discussion started by: Chaitrali
4 Replies

2. Shell Programming and Scripting

split and rename the file

Hi All, I have a requirement .I want to split a file and the split files should have certain names. Currently when i use the split command split -1000 testdata testdata_ Then the output is testdata_aa testdata_bb testdata_cc and so on. But i want the output as testdata1.snd... (3 Replies)
Discussion started by: dnat
3 Replies

3. Shell Programming and Scripting

awk split and rename files

I have a file test1.html like below: <dctm_topnav_en_US> <html> ..... </html> <dctm_topnav_en_CA> <html> ..... </html> <dctm_topnav_en_FR> <html> ..... </html> I need to use awk to split this into three file names like en_US.html , en_CA.html, en_FR.html each having content between... (4 Replies)
Discussion started by: vijay52
4 Replies

4. Shell Programming and Scripting

Help with rename header content based on reference file problem

I got long list of reference file >data_tmp_number_22 >data_tmp_number_12 >data_tmp_number_20 . . Input file: >sample_data_1 Math, 5, USA, tmp SDFEWRWERWERWRWER FSFDSFSDFSDGSDGSD >sample_data_2 Math, 15, UK, tmp FDSFSDFF >sample_data_3 Math, 50, USA, tmp ARQERREQR . . Desired... (7 Replies)
Discussion started by: perl_beginner
7 Replies

5. Shell Programming and Scripting

split file content

Hi All; I have input file like below name char(3) number number(3) inputfile namenumber xyz123abc509kai330 aca203 ald390afa000als303 I wanted to split like below:- output like this:- xyz123 abc509 kai330 aca203 ald390 (6 Replies)
Discussion started by: Jairaj
6 Replies

6. Shell Programming and Scripting

Split the file based on the content

Arun kumar something somehting Enterting in to the line . . . . Some text text Finshing the sentence Some other text . . . . Again something somehting Enterting in to the line . . . . . . Again text text Finshing the sentence (6 Replies)
Discussion started by: arukuku
6 Replies

7. Shell Programming and Scripting

split file content into specific folders

Hi I have a large text file and I want to split its content into multiple flies. this large file contains several blocks of codes separated by a comment line for each block. this comment line represents a directory path So, when separate these blocks each into a separate file, This output... (7 Replies)
Discussion started by: turki_00
7 Replies

8. Shell Programming and Scripting

[awk] split file1 and save it as var from file2

I have 2 files: file_1: file_2: expected result: name file: "artV1" "artV2" etc. I have: but why don;t work save to file 'out'?? (3 Replies)
Discussion started by: ffresz
3 Replies

9. Shell Programming and Scripting

How to save sorted content of a inside the same file?

Hi All, When i use sort Test, here is the output: $ sort Test a b b c d e f g h i But the contents in the file remain unsorted, how to do that? ]$ cat Test g i (6 Replies)
Discussion started by: chandrakanth
6 Replies

10. Shell Programming and Scripting

Replace content from a file and save

Hi, Right now there is a file called 'qm.ini' which is owned by mqm:mqm and I am trying to replace a line from this file with something else and save. I am using the below perl command to replace and save within a shell script with a different user called 'mqadm' which is also part of mqm... (1 Reply)
Discussion started by: bdpl
1 Replies
SVN_COMMIT(3)								 1							     SVN_COMMIT(3)

svn_commit - Sends changes from the local working copy to the repository

SYNOPSIS
array svn_commit (string $log, array $targets, [bool $recursive = true]) DESCRIPTION
Commits changes made in the local working copy files enumerated in the $targets array to the repository, with the log message $log. Direc- tories in the $targets array will be recursively committed unless $recursive is set to FALSE. Note This function does not have any parameters for specifying authentication, so a username and password must be set using svn_auth_set_parameter(3) PARAMETERS
o $log - String log text to commit o $targets - Array of local paths of files to be committed Warning This parameter must be an array, a string for a single target is not acceptable. Note Relative paths will be resolved as if the current working directory was the one that contains the PHP binary. To use the calling script's working directory, use realpath(3) or dirname(__FILE__). o $recursive - Boolean flag to disable recursive committing of directories in the $targets array. Default is TRUE. RETURN VALUES
Returns array in form of: array( 0 => integer revision number of commit 1 => string ISO 8601 date and time of commit 2 => name of committer ) Returns FALSE on failure. NOTES
Warning This function is EXPERIMENTAL. The behaviour of this function, its name, and surrounding documentation may change without notice in a future release of PHP. This function should be used at your own risk. EXAMPLES
Example #1 Basic example This example commits the calculator directory to a repository, using the username Bob and the password abc123 (hopefully, his pass- word is stronger): <?php svn_auth_set_parameter(SVN_AUTH_PARAM_DEFAULT_USERNAME, 'Bob'); svn_auth_set_parameter(SVN_AUTH_PARAM_DEFAULT_PASSWORD, 'abc123'); var_dump(svn_commit('Log message of Bob's commit', array(realpath('calculator')))); ?> The above example will output: array( 0 => 1415, 1 => '2007-05-26T01:44:28.453125Z', 2 => 'Bob' ) SEE ALSO
svn_auth_set_parameter(3), SVN documentation on svn commit. PHP Documentation Group SVN_COMMIT(3)
All times are GMT -4. The time now is 05:58 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy