The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > OS Specific Forums > HP-UX
Google UNIX.COM


HP-UX HP-UX (Hewlett Packard UniX) is Hewlett-Packard's proprietary implementation of the Unix operating system, based on System V.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
unix script for loading a data from a file into database grajesh_955 Shell Programming and Scripting 5 3 Weeks Ago 08:49 PM
Split large file and add header and footer to each small files ashish4422 Shell Programming and Scripting 7 07-07-2008 11:13 AM
Split large file and add header and footer to each file ashish4422 Shell Programming and Scripting 1 04-15-2008 03:12 AM
unix script to takes the old data from a TXT file and compress them into new file vpandey Shell Programming and Scripting 2 03-05-2008 08:10 AM
Split A Large File nbvcxzdz Shell Programming and Scripting 4 11-14-2005 05:48 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 03-29-2006
Registered User
 

Join Date: Mar 2006
Posts: 1
Need to split a large data file using a Unix script

Greetings all:
I am still new to Unix environment and I need help with the following requirement.

I have a large sequential file sorted on a field (say store#) that is being split into several smaller files, one for each store. That means if there are 500 stores, there will be 500 files. This is being done using a SQR program right now. How is this done using a Unix script? Any Pseudocode will be appreciated.

In the below example, the first two records are written to a file and when there's a change in the store#, it writes to an other file. The names of the files are lgXXX where XXX is the store number (i.e, lg002, lg003 and so on).


Format of the input file:
Store# City ZIP
--------------------
002 XXX 01601 ..> written to lg002 file
002 YYY 01601 ..> written to lg002 file
003 AAA 11111 ..> written to lg003 file
004 BBB 11222 ..> written to lg004 file
:
:
:
555 XYZ 99999 ..> written to lg555 file

Thank you!
SaiK
Reply With Quote
Forum Sponsor
  #2  
Old 03-29-2006
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,029
Code:
#!/bin/ksh

while read store city zip
do
    echo "${store} ${city} ${zip}" >> "lg${store}"
done < myInputFile
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 04:42 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0