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
Shell Programming and Scripting nivas Shell Programming and Scripting 20 02-27-2008 06:36 AM
Shell Programming and Scripting nivas Shell Programming and Scripting 21 02-25-2008 06:27 AM
Shell Programming and Scripting nivas Shell Programming and Scripting 2 02-20-2008 02:59 AM
Shell Programming and Scripting nivas Shell Programming and Scripting 3 02-13-2008 08:10 AM
Shell scripting & programming languages aloysius1001 UNIX Desktop for Dummies Questions & Answers 1 02-19-2002 12:04 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-19-2008
nivas
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
Shell Programming and Scripting

Hi,

iam having the file as follows:

ABCDEFGH|0987654321234567
ABCDEFGH|0987654321234523
ABCDEFGH|0987654321234556
ABCDEFGH|0987654321234545
POIUYTRE|1234567890890678
POIUYTRE|1209867757352567
POIUYTRE|5463879088797131
POIUYTRE|5468980091344456



pls provide me the split command


I want to split this abouve file as per the 1-8 character.

o/p file should

file1

ABCDEFGH|0987654321234567
ABCDEFGH|0987654321234523
ABCDEFGH|0987654321234556
ABCDEFGH|0987654321234545
file2
POIUYTRE|1234567890890678
POIUYTRE|1209867757352567
POIUYTRE|5463879088797131
POIUYTRE|5468980091344456
  #2 (permalink)  
Old 02-19-2008
anchal_khare anchal_khare is online now
Registered User
  
 

Join Date: Jun 2007
Location: Mumbai,India
Posts: 325
do u want ur file in two parts from the middle??

ur req "1-8 character." is not clear...
Pl explain..
  #3 (permalink)  
Old 02-19-2008
nivas
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
as i said above after spliting process i need 2 seperate files file1 and file2
  #4 (permalink)  
Old 02-19-2008
anchal_khare anchal_khare is online now
Registered User
  
 

Join Date: Jun 2007
Location: Mumbai,India
Posts: 325
if ur file is same as u said..
thn use this..
split -l 4 file.txt

now there 'll be two files with names xaa and xab with the contents u want

Anchal.
  #5 (permalink)  
Old 02-19-2008
nivas
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
For testing purpose i have given only 4 records,

actually it may be in lacs...what is the method in that case??
  #6 (permalink)  
Old 02-19-2008
knijjar knijjar is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 27
split -l is the best options, do a man on split and read the -l option.



The following options are supported:

-linecount | -l linecount
Number of lines in each piece. Defaults to 1000 lines.

1) wc filename ( one you know the total # of lines you can decide on splitting them in either 2 or 2 or n number of smaller files.

For example if your file has 100000 lines

split -l 50000 filename will give you two file xaa and xab with 50000 lines each.

if you do

split -l 20000 filename it will give you xaa, xab , xac, xad, xae files with exactly 20000 lines in each file.

I hope this helps.
  #7 (permalink)  
Old 02-19-2008
agn agn is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 172
Code:
for i in $(cut -d'|' -f 1 test | sort | uniq); do grep ^$i test > ${i}.txt; done
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 11:13 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