Sponsored Content
Top Forums Shell Programming and Scripting Need help to create multiple file using shell script Post 302737389 by jagguvarma on Thursday 29th of November 2012 12:16:48 AM
Old 11-29-2012
Linux Need help to create multiple file using shell script

HI,

i created the below script to create the multiple files, iam not getting the required output, Please advice.

Code:
#!/bin/sh
v_date=$1 # argument will come as daymonthyear eg : 151112
v_day=`echo $v_date | cut -c 1-2`
v_mon=`echo $v_date | cut -c 3-4`
v_year=`echo $v_date | cut -c 5-6`
if [ $v_mon -eq 1 -o $v_mon -eq 3 -o $v_mon -eq 5 -o $v_mon -eq 7 -o $v_mon -eq 8 -o $v_mon -eq 10 -o $v_mon -eq 12 ];then
v_last_day=31
elif [ $v_mon -eq 4 -o $v_mon -eq 6 -o $v_mon -eq 9 -o $v_mon -eq 11 ];then
v_last_day=30
elif [ $v_mon -eq 2 ];then
v_last_day=28
fi
if [ $v_day -le 9 ];then
touch SkyOffer_Details_0{$v_day..9}$v_monv_year.txt
touch SkyOffer_Details_{10..$v_last_day}$v_mon$v_year.txt
else
touch SkyOffer_Details_{$v_day..$v_last_day}$v_mon$v_year.txt
fi

Hint : touch SkyOffer_Detail_{8..30}1112.txt this command creates the multiple files as below, but i want to do it as dynamically, so iam going for a script
Code:
SkyOffer_Details_81112.txt
SkyOffer_Details_91112.txt
SkyOffer_Details_101112.txt
SkyOffer_Details_111112.txt
..............
..............
...........
SkyOffer_Details_291112.txt
SkyOffer_Details_301112.txt

required output :

if argument is 081112, i want 0 byte files as
Code:
SkyOffer_Details_081112.txt
SkyOffer_Details_091112.txt
SkyOffer_Details_101112.txt
SkyOffer_Details_111112.txt
..............
..............
...........
SkyOffer_Details_291112.txt
SkyOffer_Details_301112.txt

script execution : when i executed the above script as

./script_name 081112

executed Output : scripts is creating the zero byte file as
SkyOffer_Detail_{8..30}1112.txt

but i want the output as
Code:
SkyOffer_Details_081112.txt
SkyOffer_Details_091112.txt
SkyOffer_Details_101112.txt
SkyOffer_Details_111112.txt
..............
..............
...........
SkyOffer_Details_291112.txt
SkyOffer_Details_301112.txt

COuld anyone help me to solve this.

Thank you.

Jagadeesh

Last edited by Scott; 11-29-2012 at 01:26 AM.. Reason: Please use code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need a Shell script to create Multiple User Accounts

Hi All, Am New to shell scripting , Can u please Help me to Create a shell script which Creates Multiple Users (say up to 250 users) ,am using Rehat server 5 enterprise Edition .. I am really in need of this script So tat i can save time and effort for this Job .. KIndly help me Please ... (1 Reply)
Discussion started by: rksubash
1 Replies

2. Shell Programming and Scripting

how to create csv file using shell script

I have a file in multiple directory which has some records in the following format File: a/latest.txt , b/latest.txt, c/latest.txt -> Name=Jhon Age=27 Gender=M Street=LA Road Occupation=Service I want to generate a csv file from the above file as follows File: output.csv -> ... (9 Replies)
Discussion started by: rjk2504
9 Replies

3. Shell Programming and Scripting

A shell script for create a a file in the respective path

Hello forum members, I have to create a out file in the current path./aaa/bbb/ccc/hhh. i am writing script below. ###script Begins##### #!/bin/ksh echo "Weclome" if then echo "Hello" rm -rf $aaa/bbb/ccc/hhh #clean the exsisting o/p file echo "no... (2 Replies)
Discussion started by: rajkumar_g
2 Replies

4. Shell Programming and Scripting

Shell script to create multiple OpenSSL Certificates

I need to create a script that will generate a bunch of OpenSSL Certificates signed by my own CA. The certificates being generated are for testing purposes only. But what I need is the following Root CA 512 768 1024 1280 1536 1792 2048 4096 I need basically 64 combinations. Each... (4 Replies)
Discussion started by: krisarmstrong
4 Replies

5. Shell Programming and Scripting

Create shell script to extract unique information from one file to a new file.

Hi to all, I got this content/pattern from file http.log.20110808.gz mail1 httpd: Account Notice: close igchung@abc.com 2011/8/7 7:37:36 0:00:03 0 0 1 mail1 httpd: Account Information: login sastria9@abc.com proxy sid=gFp4DLm5HnU mail1 httpd: Account Notice: close sastria9@abc.com... (16 Replies)
Discussion started by: Mr_47
16 Replies

6. Programming

help need in the perl script that create one xml file form multiple files.

Hi every one, Please excuse me if any grammatical mistakes is there. I have multiple xml files in one directory, I need to create multiple XML files into one XML file.example files like this</p> file1:bvr.xml ... (0 Replies)
Discussion started by: veerubiji
0 Replies

7. Shell Programming and Scripting

How to create a shell script to read a foldername from a text file and go to the folder?

Hi, I am trying to write a shell script which can read folder names from a text file and then go to the folder and picks up a xml file and write on my sipp script so that I can run the sipp script. For example: I have a text file called thelist.txt where I have provided all the folders... (7 Replies)
Discussion started by: pm1504
7 Replies

8. UNIX for Dummies Questions & Answers

How to Create excel file(.csv) using shell script?

Hi, i have shell script which compiles n number of test cases and execute them one by one. i want to create report in excel through script in which two columns namely "test id" and "release".second column have two subcolumns namely compiles and excutes. so i want first column should display test... (15 Replies)
Discussion started by: RamMore123
15 Replies

9. Shell Programming and Scripting

Create a UNIX script file with multiple commands

Hi Good morning all, I want to create script file with multiple commands. For ex: pmrep connect is one of the command to connect to repository. pmrep objectexport is another command to export objects to a file. These commands should run sequentially.But when i try to execute this, the first... (4 Replies)
Discussion started by: SekhaReddy
4 Replies

10. Shell Programming and Scripting

Create file from script shell

Hello all :) Here is my code i try to complete: address1="$(ssh root@$machine -x "lxc-info -n $machine-worker1 -H -i")" if //ifthe file addrfile does not exist then create the file addrfile echo "$address1">"$addrfile" fi "$address1">"$addrfile" How, can i... (4 Replies)
Discussion started by: chercheur111
4 Replies
ATF-SH(1)						    BSD General Commands Manual 						 ATF-SH(1)

NAME
atf-sh [-s shell] -- interpreter for shell-based test programs SYNOPSIS
atf-sh script DESCRIPTION
atf-sh is an interpreter that runs the test program given in script after loading the atf-sh(3) library. atf-sh is not a real interpreter though: it is just a wrapper around the system-wide shell defined by ATF_SHELL. atf-sh executes the inter- preter, loads the atf-sh(3) library and then runs the script. You must consider atf-sh to be a POSIX shell by default and thus should not use any non-standard extensions. The following options are available: -s shell Specifies the shell to use instead of the value provided by ATF_SHELL. ENVIRONMENT
ATF_LIBEXECDIR Overrides the builtin directory where atf-sh is located. Should not be overridden other than for testing purposes. ATF_PKGDATADIR Overrides the builtin directory where libatf-sh.subr is located. Should not be overridden other than for testing purposes. ATF_SHELL Path to the system shell to be used in the generated scripts. Scripts must not rely on this variable being set to select a specific interpreter. EXAMPLES
Scripts using atf-sh(3) should start with: #! /usr/bin/env atf-sh Alternatively, if you want to explicitly choose a shell interpreter, you cannot rely on env(1) to find atf-sh. Instead, you have to hardcode the path to atf-sh in the script and then use the -s option afterwards as a single parameter: #! /path/to/bin/atf-sh -s/bin/bash ENVIRONMENT
ATF_SHELL Path to the system shell to be used in the generated scripts. SEE ALSO
atf-sh(3) BSD
September 27, 2014 BSD
All times are GMT -4. The time now is 05:50 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy