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
c program to extract text between two delimiters from some text file kukretiabhi13 High Level Programming 7 12-03-2008 06:29 PM
Split large file and add header and footer to each file ashish4422 Shell Programming and Scripting 1 04-15-2008 06:12 AM
Split a file with no pattern -- Split, Csplit, Awk madhunk UNIX for Dummies Questions & Answers 10 12-17-2007 12:57 PM
grep multiple text files in folder into 1 text file? coppertone UNIX for Dummies Questions & Answers 7 08-23-2002 02:50 PM
Split text file by pages ranri UNIX for Dummies Questions & Answers 2 06-01-2001 02:43 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-15-2007
ihot ihot is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 19
efficiently split a 2GB text file into two

Can an expert kindly write an efficient Linux ksh script that will split a large 2 GB text file into two?
Here is a couple of sample record from that text file:
"field1","field2","field3",11,22,33,44
"TG","field2b","field3b",1,2,3,4

The above rows are delimited by commas.

This script is to search the first field for the word "TG". If that row is present, it is to load that row to a TG.txt file. If this first field is not "TG", then it is to load that row into a NoTG.txt file.

So the result is a new TG.txt with the following row:
"TG","field2b","field3b",1,2,3,4

and a new NoTG.txt with the following row:
"field1","field2","field3",11,22,33,44

Thanks in advance. This forum rocks - with lots of helpful heroes!!
  #2 (permalink)  
Old 10-15-2007
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
Code:
awk '{ if (index($0,"\"TG\",")==1) {print > "TG.txt" } else {print > "NoTG.txt"} }' bigfile
  #3 (permalink)  
Old 10-15-2007
ihot ihot is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 19
Thanks a million!!

Thanks a million!! That was so simple and elegant. So sorry to take up time from your busy schedule. I do pay back by answering questions in other VBA/ Essbase forums where I have greater expertise.

Pushing my luck with one last question:
Can you expand on this KSH (kshell) script to exclude rows that have blanks instead of numbers? For example, exclude rows looking like this:

"TG","field2c","field3c",,,,
"TG","field2b","field3b",,,,

where the last four fields are blanks.
Thanks in advance.
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:06 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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