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
Please Help:Need to Split the file into mutliple files depends on the KEY field value arund_01 UNIX for Dummies Questions & Answers 14 04-23-2008 03:42 PM
Split file into multiple files depending upon first 4 digits deepakgang Shell Programming and Scripting 4 04-09-2008 01:21 AM
Help Needed : Split one big file to multiple files monicasgupta Shell Programming and Scripting 5 03-03-2008 07:09 PM
Split File into seperate files eltinator Shell Programming and Scripting 4 08-03-2007 02:27 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 Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-02-2007
dummy_needhelp dummy_needhelp is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 23
Split A File Into 2 Files

i WANT TO SPLIT A FILE WHICH HAS 250 COLUMNS. and the delimiter is '|'. So , can somebody help me with the command i have to use to split the file into two files.

thanks
  #2 (permalink)  
Old 11-02-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
Which columns are going into which output files, in what format and in which column order?
  #3 (permalink)  
Old 11-03-2007
matrixmadhan matrixmadhan is online now Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,944
Are these two posts related ?

have a file with 300 columns
  #4 (permalink)  
Old 11-03-2007
lione.heart lione.heart is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 13
cat FILE | awk -F\| '{for(i=1;i<125;i++) printf "%s ",$i; printf"\n"}' > firs125col.log
cat FILE | awk -F\| '{for(i=125;i<251;i++) printf "%s ",$i; printf"\n"}' > second125col.log

have a nice day
  #5 (permalink)  
Old 11-03-2007
matrixmadhan matrixmadhan is online now Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,944
Quote:
Originally Posted by lione.heart View Post
cat FILE | awk -F\| '{for(i=1;i<125;i++) printf "%s ",$i; printf"\n"}' > firs125col.log
cat FILE | awk -F\| '{for(i=125;i<251;i++) printf "%s ",$i; printf"\n"}' > second125col.log

have a nice day
UUOC,

use it like,

awk '{}' filename > outputfilename
  #6 (permalink)  
Old 11-04-2007
dummy_needhelp dummy_needhelp is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 23
Yes, Those two posts are related. And i still didnt understand . Can anyone explain in clear. Or can anyone give me a clear code
Thanks
  #7 (permalink)  
Old 11-04-2007
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,414
The following code split the inputfile (with '|' as field separator FS) into two files first125cols.dat and last125cols.dat (with '|' as field separator OFS).

Code:
awk -v FS='|'  -v OFS='|' '
{
   # Write first 125 cols

   for (field=1; (field<=125 && field<=NF); field++)
      line = line (field>1 ? OFS : "") $field;
   print line > "first125cols.dat"

   # Write last 125 cols

   for (field=125; (field<=255 && field<=NF); field++)
      line = line (field>1 ? OFS : "") $field;
   print line > "last125cols.dat"
}
' inputfile
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 12:48 PM.


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