splitting newfile.txt file and executing each splitted files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting splitting newfile.txt file and executing each splitted files
# 1  
Old 03-01-2012
splitting newfile.txt file and executing each splitted files

Code:
split -l $split_count newfile.txt        
    for i in $split_files*
       do
            if  test -s $workingdir/$split_files*
             then
                     ./<$i.out>                             
             fi                                 
                  
       done

1.split the newfile.txt file into multiple files using split cmd(say splitcount=50)
2. check if content of the split files is empty or not
3. If it is not empty execute the file

Moderator's Comments:
Mod Comment How to use code tags

Last edited by Franklin52; 03-01-2012 at 06:24 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 03-01-2012
So, what is the problem you are facing?

probably, you might need to change the following line
Code:
if test -s $workingdir/$split_files*

with

Code:
if test -s $workingdir/$i

What do you mean by "$i.out" ?
Do you want the split files to be renamed to <file>.out before executing?
# 3  
Old 03-01-2012
1.need to execute each split files.
2.for collecting and executing split files i am using for loop

what is the exact command to run the file inside for loop? I am using <$i.out> not sure it is corrrect or not

---------- Post updated at 02:37 PM ---------- Previous update was at 02:14 PM ----------

Each files contains some commands so i need to run that file

Last edited by sanjay mn; 03-01-2012 at 04:49 AM..
# 4  
Old 03-01-2012
In that case, you have to make sure that :


The command doesn't have any dependency with other commands.

Each split file must also be a valid script.

You have to check shell and version dependencies for the command you are using and use appropriate invocation of that shell from the command line mode since it doesn't contains the shebang.

Code:
cd $workingdir
for i in $split_files*
do
 if [ -s $i ]  ;then
  bash $i
 fi 
done

You requirement doesn't seem to be real. If your final goal is something else, please let us know so that we can help you better.
# 5  
Old 03-01-2012
Each split files contains list of eval commands.so i want to run that files.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Combine splitted low & high byte files into one file

Hi all, i have a binary file splitted into 2 chunks, first part with all high bytes and the second part with all low bytes. I need to combine the two chunks into one binary file like (eg. exactly the reverse of the splitting method solved in the thread # 130940) Hi bytes file content:... (7 Replies)
Discussion started by: mzs
7 Replies

2. UNIX for Dummies Questions & Answers

Write pid and command name to a txt file while executing a bash script

Hi All, Just have a requirement, I am executing a bash shell script, my requirement is to catch the pid and job name to a txt file in the same directory, is there anyway to do it? please help me out. Regards Rahul ---------- Post updated at 08:42 AM ---------- Previous update was at... (2 Replies)
Discussion started by: rahulkalra9
2 Replies

3. Shell Programming and Scripting

Script to multi-transfer splitted files via scp

Hey :3 I am moving some stuff between different servers. I do it like this: scp -r -P 22 -i ~/new.ppk /var/www/bigfile.tar.gz user@123.123.123.123:/var/www/bigfile.tar.gz Lets say, this file is 50 GiB. I would like to know, if its possible to split the file in different parts,... (2 Replies)
Discussion started by: Keenora
2 Replies

4. Shell Programming and Scripting

Splitting file into 2 files ?

Hi extending to one of my previous posted query .... I am using nawk -v invar1="$aa" '{print > ("ABS\_"((/\|/)?"A\_":"B\_")invar1"\_NETWORKID.txt")}' spfile.txt to get 2 different files based on split condition i.e. "|" Similar to invar1 variable in nawk I also need one more variable... (18 Replies)
Discussion started by: shekharjchandra
18 Replies

5. Shell Programming and Scripting

Need Header for all splitted files - awk

Input file: i have a file and need to split into multiple files based on first column. i need the header for all the splitted files. I'm unable to get the header. $ cat log.txt id,mailtype,value 1252468812,yahoo,3.5 1252468812,hotmail,2.4 1252468819,yahoo,1.2 1252468812,msn,8.9... (6 Replies)
Discussion started by: mannefromdetroi
6 Replies

6. Shell Programming and Scripting

Splitting files from one file

Hi, I have an input file like: 111 abcdefgh asdfghjk dfghjkl 222 aaaaaaa bbbbbb 333 djfhfgjktitjhgfkg 444 djdhfjkhfjkghjkfg hsbfjksdbhjkgherjklg fjkhfjklsahjgh fkrjkgnj I want to read this input file and make separate output files with the header as numric value like "111"... (9 Replies)
Discussion started by: saltysumi
9 Replies

7. Shell Programming and Scripting

sed *.csv from file > newfile with /n

I have a an output file with a format: something blah1.csv blah2.csv blah3.csv somethingelse and I'm trying to use sed to pull all the *.csv entries out and put them 1 per line on a new file. I can't quite figure out how to write them to a new file with carriage returns, is there a simple way... (8 Replies)
Discussion started by: unclecameron
8 Replies

8. Shell Programming and Scripting

How to compare 2 file to newfile......

Hi all Member i want compare 2 file to newfile I am new to shell script, just wanted you guy to help. example file A CM-00000BN_Oth-VAS-0000392 CM-00000BNSEED_Oth-Spe-0000392 CM-00000KJ_Pos-Pro-0000806 CM-00000KJ_Pos-Pro-0000810 CM-00000KJ_Pos-Pro-0000812 CM-00000KJ_Pos-Pro-0000814... (1 Reply)
Discussion started by: ooilinlove
1 Replies

9. UNIX for Dummies Questions & Answers

How to restore splitted DD file

I backup a file to tape by using "dd", since the size is too large it took two tape for the backup, the question is how to restore the said file? The "dd" doesn't ask me insert next tape while restoration. (3 Replies)
Discussion started by: coolmans
3 Replies

10. UNIX for Dummies Questions & Answers

Splitting a txt file

HI! all I have a text file which contains 90,000 records.my requirement is to split this file in to four parts becuse according to an requirement a file should contain 25,000 records only .After splitting i need to concatenate the timestamp with the file name , Plese can any 1 help me ... (6 Replies)
Discussion started by: mohdtausifsh
6 Replies
Login or Register to Ask a Question