Create a .sh file for an equivalent Excel VBA code


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Create a .sh file for an equivalent Excel VBA code
# 1  
Old 02-17-2012
Create a .sh file for an equivalent Excel VBA code

Hi guys,
I am new to Unix, Need your help here.
I have installed cygwin software (Unix) in my computer (Windows vista). Now i want to create a shell script (.sh file)/other script which is equivalent of VBA code (at the bottom) and then put this .sh file into bin directory of c:/cygwin.
so when i login into cygwin and type some command, it should be able to perform the same function as in VBA code.
Please help me out with this script and its programming.

VBA code:
Code:
Sub Macro3()
    sFile = Application.GetOpenFilename("All files (*.*), *.*", 1,  "Select Input File", "Open", False)         'asks for file location
    If TypeName(sFile) = "Boolean" Then             ' if input file "Kget_utran cell" is not provided, exit.
        Exit Sub
    End If
    f = FreeFile
    Open sFile For Input As f
    strfile = Input(LOF(f), #f)     ' read whole file into variable
    Close f    ' no need to keep file open
    Do
      strt = Strings.InStr(strfile, "Bye...")       'Gives start value of this string in the input file.
      If strt = 0 Then Exit Do    ' not found finish
      nd = InStr(strt, strfile, ".log") + 5
      pp = Mid(strfile, (strt - 16), (nd - strt + 16))
      strfile = Replace(strfile, pp, "")
    Loop
    Length = Len(sFile)
    j = 1
    rr = 1
    Do Until rr = 0
        rr = InStr(j, sFile, "\")
        If rr = 0 Then
            GoTo here
        End If
        j = rr + 1
    Loop
here:    y = Left(sFile, j - 2)
    Open y & "\output.txt" For Output As f      'saves at this location
    Print #f, strfile
    Close f
    MsgBox "DONE"
End Sub


Last edited by Franklin52; 02-17-2012 at 04:25 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 02-17-2012
provide the input file contents and the expected output format
# 3  
Old 02-17-2012
Hi,
Thanks a lot for replying.
I have attached input & output file in a zip file.

I have a input file (.log/.txt format) which is located in the C:\cygwin\home\ebanpan. so when i login into cygwin software, i need to type some command to perform "deletion of few lines" on this input file and after performing the deletion save the output file at the same location.
the line which need to be deleted is
"
Total: 921 MOs

Bye...
Output has been logged to file /var/opt/ericsson/amos/moshell_logfiles/v46248C/logs_mobatch/2012-01-20/site.mo/15-38/CTL01274.log

"

basically this line is repeated multiple times in the input file which i need to delete. but this line is not fixed, start and end words of this line are fixed. i am also pasting one more line below so you can compare these two lines and find out which words will be fixed and which can change.
"
Total: 926 MOs

Bye...
Output has been logged to file /var/opt/ericsson/amos/moshell_logfiles/v46248C/logs_mobatch/2012-01-20/site.mo/15-38/CTL01270.log

"
I hope you would be able to help me out. If you have any other questions/issues please let me know.
Thanks again.
# 4  
Old 02-17-2012
Code:
sed '/^Total/d;/^Bye/d;/^Output has been logged/d' input.txt > output.txt

# 5  
Old 02-17-2012
Hi,
thanks for replying.
I am new to Unix. it would be lot of help, if you can help me out with your reply.
i mean, what do u want me to do with this command.??

should i write this into a notepad and then save this file with .sh extension??

Thanks,
# 6  
Old 02-17-2012
yes

save the below contents into a file and save it as .sh

Code:
 
inputfile="$1"
ouputfile="$2"
sed '/^Total/d;/^Bye/d;/^Output has been logged/d' $1 > $2

run the script as

Code:
 
./script.sh inputfile.txt ouptut.txt

# 7  
Old 02-17-2012
Hi,
i created .sh file with your code.
but i don't understand about the code
"./script.sh inputfile.txt ouptut.txt"
where should i use this script. sorry to bother you.

i have also attached cygwin snapshot, it may be of any use.
Create a .sh file for an equivalent Excel VBA code-cygwin-snapjpg
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Windows & DOS: Issues & Discussions

Update sh file using VBA before perl script is run

I have a VBA that creates a new directory folder and creates a new text file in that directory. I am trying to run a perl script from the VBA and have created a batch file that gets called from the VBA. That bat file uses a shell file to run a script. When the batch file is called I get the error... (0 Replies)
Discussion started by: cmccabe
0 Replies

2. Windows & DOS: Issues & Discussions

Excel VBA script aware of being opened interatively or from the command line

I have a Excel VBA script that automatically runs when opened, extracts one table from a Microsoft Access Database, saves it as CSV, closes it, extracts another, saves it as CSV, closes it, then terminates itself. Is is called from a short .bat file using the /e option so that Excel does not... (1 Reply)
Discussion started by: Michael Stora
1 Replies

3. 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

4. Shell Programming and Scripting

Create excel file using bash script

i have written one script which generates text file which gives output like. 001.config: CR1.1 COMPILE_PASSED TEST_PASSED 002.config: CR1.1 COMPILE_FAILED TEST_FAILED . . .so on this text file will get filled one by one as its for loop for n number. i... (7 Replies)
Discussion started by: RamMore123
7 Replies

5. UNIX for Dummies Questions & Answers

Create the equivalent of the command WC

hi all, i'm trying to do this exercise, i want to create a script that can substitute WC command in unix, can someone help me? (11 Replies)
Discussion started by: Marina2013
11 Replies

6. Shell Programming and Scripting

create separate files from one excel file with multiple sheets

Hi, I have one requirement, create separate files (".csv") from one excel file(xlsx) with multiple sheets. These ".csv" files are my source files. So anybody please suggest me the process. Thanks in Advance. Regards, Harris (3 Replies)
Discussion started by: harris
3 Replies

7. Shell Programming and Scripting

Create an .csv/excel file using shellscript

In my file, i have 4 Product names(For ex:Microsoft excel, Oracle,.Net,IBM websphere,..etc.,) I want this 4 Products in 4 individual .csv/excel file after running the script with those products related information. (12 Replies)
Discussion started by: Navya
12 Replies

8. UNIX for Dummies Questions & Answers

create excel file

Hi, How can I create an excel file from a txt file using shell script. Please do a help for me. Thanks, Regards, Milton (6 Replies)
Discussion started by: miltony
6 Replies

9. UNIX for Advanced & Expert Users

Hw to create root-equivalent accounts?

Hi all. After installing ssh on a server, i'd like to create a user with root privileges. My problem is that after creating a user rootssh (uid=0, gid=20, /home/rootshh), i make rootssh's ssh keys. The problem is that normally the ssh-keygen should create the keys under $HOME/.ssh/, and actually... (6 Replies)
Discussion started by: penguin-friend
6 Replies
Login or Register to Ask a Question