Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can split a single file into multiple files? 1

Status
Not open for further replies.

tbtcust

Programmer
Oct 26, 2004
214
US
Hello all,

I have a single source file that I want to split into multiple target files. The source file will vary and contain the target path and file names. See below for details.

I want to create generic process that will not rely on hardcoded target path and file names. Is this possible?

Thanks in advance for any help

Source File will look like this
/user_path_1/ | file_nname_1.txt/ | Data1 Data1 Data1 Data1 Data1 Data1 Data1 Data1
/user_path_1/ | file_nname_1.txt/ | Data1 Data1 Data1 Data1 Data1 Data1 Data1 Data1
/user_path_1/ | file_nname_1.txt/ | Data1 Data1 Data1 Data1 Data1 Data1 Data1 Data1
/user_path_2/ | file_nname_2.txt/ | Data2 Data2 Data2 Data2 Data2 Data2 Data2 Data2
/user_path_2/ | file_nname_2.txt/ | Data2 Data2 Data2 Data2 Data2 Data2 Data2 Data2
/user_path_2/ | file_nname_2.txt/ | Data2 Data2 Data2 Data2 Data2 Data2 Data2 Data2
/user_path_3/ | file_nname_3.txt/ | Data3 Data3 Data3 Data3 Data3 Data3 Data3 Data3
/user_path_3/ | file_nname_3.txt/ | Data3 Data3 Data3 Data3 Data3 Data3 Data3 Data3
/user_path_3/ | file_nname_3.txt/ | Data3 Data3 Data3 Data3 Data3 Data3 Data3 Data3


The target files will look contain the data like this
/user_path_1/file_nname_1.txt
Data1 Data1 Data1 Data1 Data1 Data1 Data1 Data1
Data1 Data1 Data1 Data1 Data1 Data1 Data1 Data1
Data1 Data1 Data1 Data1 Data1 Data1 Data1 Data1

/user_path_2/file_nname_2.txt
Data2 Data2 Data2 Data2 Data2 Data2 Data2 Data2
Data2 Data2 Data2 Data2 Data2 Data2 Data2 Data2
Data2 Data2 Data2 Data2 Data2 Data2 Data2 Data2

/user_path_3/file_nname_3.txt
Data3 Data3 Data3 Data3 Data3 Data3 Data3 Data3
Data3 Data3 Data3 Data3 Data3 Data3 Data3 Data3
Data3 Data3 Data3 Data3 Data3 Data3 Data3 Data3
 
Hi

Code:
awk -F '/? *\\| *' 'f!=$1[green][i]"/"[/i][/green]$2{[b]if[/b](f)[b]close[/b](f);f=$1[green][i]"/"[/i][/green]$2}{[b]print[/b]$3>f}' /input/file


Feherke.
feherke.github.io
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top