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
Generating a Subsystem funksen AIX 0 07-14-2008 04:43 AM
Generating xls with utf-8 format kalyanramurs Shell Programming and Scripting 0 06-21-2008 07:27 AM
Generating files with time interval of fifteen minutes aajan Shell Programming and Scripting 0 09-25-2007 01:54 AM
Generating files of specific size nxd25 Shell Programming and Scripting 2 06-27-2006 11:06 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 09-20-2008
anushree.a anushree.a is offline
Registered User
  
 

Join Date: May 2008
Posts: 87
Generating files.

I/P file name:- 20092008.txt
Check number of entries in i/p file by following command
ChkEnt –infl 20092008.txt -opfl 20092008_test.txt >count.txt

Dear Friends,
Please help me in automating following thing.

If output generated (count.txt) is having value more than 1000 i.e. say it has shown 3521 entries
Then, system should split file as follows

Splt –infl 20092008.txt –opfl 20092008_1.txt –b 0 –e 1000
Splt –infl 20092008.txt –opfl 20092008_2.txt –b 1001 –e 2000
Splt –infl 20092008.txt –opfl 20092008_3.txt –b 2001 –e 3000
Splt –infl 20092008.txt –opfl 20092008_4.txt –b 3001 –e 3521

Here the script should be smart enough to calculate number of files to be generated automatically by looking at total no of entries in original file i.e. 3521 in earlier example.

Thank you in advance.
I am waiting for your reply
Bye and take care
  #2 (permalink)  
Old 09-20-2008
Tytalus's Avatar
Tytalus Tytalus is offline Forum Advisor  
echo {1..9}^2\;|bc
  
 

Join Date: Jun 2003
Location: Scotland
Posts: 431
split takes a linecount parameter.....iirs the default is 1000, i.e. it will split your file into 1000 line chunks.

is this not what you are after ?
  #3 (permalink)  
Old 09-20-2008
anushree.a anushree.a is offline
Registered User
  
 

Join Date: May 2008
Posts: 87
No, my system works differently, it does not split file by line count. It works on a logic n that logic is incorporated the command that i hv mentioned i.e. Splt
  #4 (permalink)  
Old 09-20-2008
Tytalus's Avatar
Tytalus Tytalus is offline Forum Advisor  
echo {1..9}^2\;|bc
  
 

Join Date: Jun 2003
Location: Scotland
Posts: 431
aaah - you mean something like:

Code:

#  x=$(wc -l count.txt) ; y=0 

#  while [ $x -gt 1000 ]; do echo Splt -infl 20092008.txt -opfl 20092008_${y} -b $(expr $y \* 1000 + 1) -e $(expr $y \* 1000 + 1000); y=$(expr $y + 1); x=$(expr $x - 1000); done ; echo Splt -infl 20092008.txt -opfl 20092008_2 -b $(expr $y \* 1000 + 1) -e  $(expr $y \* 1000 + $x)
Splt -infl 20092008.txt -opfl 20092008_0 -b 1 -e 1000
Splt -infl 20092008.txt -opfl 20092008_1 -b 1001 -e 2000
Splt -infl 20092008.txt -opfl 20092008_2 -b 2001 -e 3000
Splt -infl 20092008.txt -opfl 20092008_2 -b 3001 -e 3521
  #5 (permalink)  
Old 09-20-2008
anushree.a anushree.a is offline
Registered User
  
 

Join Date: May 2008
Posts: 87
Dear Tytalus, thanx for your quick reply.
I m new to unix n all, so can u plz tell me following things

1. Can we use "cat" option i.e. cat count.txt to assign that count value to variable x?
e.g
x=`cat count.txt`

2. Honestly i coulnt undrstnd this statement.
while [ $x -gt 1000 ]; do echo Splt -infl 20092008.txt -opfl 20092008_${y} -b $(expr $y \* 1000 + 1) -e $(expr $y \* 1000 + 1000); y=$(expr $y + 1); x=$(expr $x - 1000); done ; echo Splt -infl 20092008.txt -opfl 20092008_2 -b $(expr $y \* 1000 + 1) -e $(expr $y \* 1000 + $x)
Can u jst tell me, is the script smart enough to handle even if a particular file has n number of records? or it can handle only 3521 entries?
  #6 (permalink)  
Old 09-20-2008
Tytalus's Avatar
Tytalus Tytalus is offline Forum Advisor  
echo {1..9}^2\;|bc
  
 

Join Date: Jun 2003
Location: Scotland
Posts: 431
no worries.

cat will simply spew the file out.

wc will give you a word count (and the -l will be the number of lines alone).

Yes - the script should work for any length file - it simply sets a variable x as the number of lines, then repeatedly subtracts 1000 and spts out each individual command, until x' is less than 100 - then the loop finishes and it kicks out the final splt command
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:22 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