The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Multiple file needed with certain file_prefix rauphelhunter Shell Programming and Scripting 6 05-27-2008 05:26 AM
Split file into multiple files depending upon first 4 digits deepakgang Shell Programming and Scripting 4 04-09-2008 01:21 AM
Help needed to sort multiple columns in one file ahjiefreak UNIX for Dummies Questions & Answers 1 12-07-2007 05:50 AM
Split A File Into 2 Files dummy_needhelp Shell Programming and Scripting 7 11-04-2007 07:36 PM
Split a file into 2 or more files bobo UNIX for Dummies Questions & Answers 4 01-16-2006 05:15 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-02-2008
monicasgupta monicasgupta is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 6
Help Needed : Split one big file to multiple files

Hi friends,

I have data in flat file as following, first filed is the customer number. We have almost 50-100 customers in the system


100 ABC A123
100 BVC D234
100 BNC N324
200 CBC A122
200 AVC D294
200 HNC N324
300 GBC A173
300 FVC D234
300 DNC N344

I want to split the file and create individual file for each customer with customer number in the file name as follows,

File Name : 100.<TimeStamp>.txt

100 ABC A123
100 BVC D234
100 BNC N324

File Name : 200.<TimeStamp>.txt

200 CBC A122
200 AVC D294
200 HNC N324

File Name : 300.<TimeStamp>.txt

300 GBC A173
300 FVC D234
300 DNC N344

I really apprciate if anyone can help me writing this script.
  #2 (permalink)  
Old 03-02-2008
Perderabo's Avatar
Perderabo Perderabo is online now Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,100
This is one line with awk...
Code:
$ ls
data
$
$
$
$
$
$ cat data
100 ABC A123
100 BVC D234
100 BNC N324
200 CBC A122
200 AVC D294
200 HNC N324
300 GBC A173
300 FVC D234
300 DNC N344
$ awk -v timestamp=whatever  '{print $0 >> ($1timestamp".txt")}'  data
$ ls
100whatever.txt 200whatever.txt 300whatever.txt data
$ cat 100whatever.txt
100 ABC A123
100 BVC D234
100 BNC N324
$
  #3 (permalink)  
Old 03-02-2008
jaduks's Avatar
jaduks jaduks is offline
Registered User
  
 

Join Date: Aug 2007
Location: Assam,India
Posts: 166
Code:
$  awk '{print > $1".ts.txt"}' cus.out
  #4 (permalink)  
Old 03-02-2008
monicasgupta monicasgupta is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 6
wow thanks Perderabo it worked like a charm!!! but it is creating one more extra file also i.e, whatever.txt. I dont want this file. I really appreciate ur input.

39 Mar 2 05:42 100whatever.txt
39 Mar 2 05:42 200whatever.txt
39 Mar 2 05:42 300whatever.txt
2 Mar 2 05:42 whatever.txt

THanks
Monica
  #5 (permalink)  
Old 03-02-2008
Perderabo's Avatar
Perderabo Perderabo is online now Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,100
Quote:
Originally Posted by monicasgupta View Post
wow thanks Perderabo it worked like a charm!!! but it is creating one more extra file also i.e, whatever.txt. I dont want this file. I really appreciate ur input.

39 Mar 2 05:42 100whatever.txt
39 Mar 2 05:42 200whatever.txt
39 Mar 2 05:42 300whatever.txt
2 Mar 2 05:42 whatever.txt

THanks
Monica
you must have some blank lines. You can ignore blank line by checking if the number of fields is non-zero....

awk -v timestamp=whatever 'NF {print $0 >> ($1timestamp".txt")}' data

And you're supposed to replace "whatever" with your timestamp.
  #6 (permalink)  
Old 03-03-2008
monicasgupta monicasgupta is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 6
Thanks Perderabo, it worked really fine, i really appreciate if you can be more helpful to me

once the file r created i need to do following two things.

1) Following file are created with data.

100whatever.txt
100 ABC A123
100 BVC D234
100 BNC N324

100whatever.txt
200 CBC A122
200 AVC D294
200 HNC N324

100whatever.txt
300 GBC A173
300 FVC D234
300 DNC N344

Now I want to remove first record from all the file, should look like
100whatever.txt
ABC A123
BVC D234
BNC N324

100whatever.txt
CBC A122
AVC D294
HNC N324

100whatever.txt
GBC A173
FVC D234
DNC N344

2) Zip all the files into one file as WHATEVER.zip

THanks
MOnica
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 10:37 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0