Creating executable script--please help


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Creating executable script--please help
# 1  
Creating executable script--please help

Hi group,
I am very beginner in shell scripting and self learning.
I am trying to create and executable script to run awk from user defined variables.

e.g. suppose from a given file I want to delete some rows or some columns
We need to repeat this process for many files. Thus I was trying to write a script. Any help will be really great.
This is my progress so far:

Code:
# A script to modify delete particular row and column from tab delim files
osch=0
echo "1. Delete row from file"
echo "2. Delete columns from file"
echo "Select your choice [1 or 2]?"
read osch
if [$osch -eq 1]; 
then
        echo "Enter row numbers with space"
        read x
        echo 'You entered this line: ' $x
        set -A rarray $x
        do 
                awk 'NR!={rarray[@]}' INPUT > INPUT_modified
        done
        echo "Modified file is created"
fi

if [$osch -eq 2]; 
then
        echo "Enter column numbers with space"
	read y
        echo 'You entered this line: ' $y
	set -A rarray $y
        for i in
        do 
	     awk '{for(i=1;i<=NF;i++)if(i!={rarray[@]})printf '%s', $i OFS;print""}' INPUT > INPUT_modified
        done
        echo "Modified file is created"
fi

As a beginner this is just a try. PLEASE HELP
Thanks a lot in advance Smilie

---------- Post updated at 12:58 PM ---------- Previous update was at 10:09 AM ----------

Any body in the group...please help. I am really stuck in here Smilie.

Last edited by smitra; 09-12-2012 at 10:43 AM..
# 2  
What is not working or what is missing? (give the output if you have errors...)
# 3  
this is the output so far...

Code:
1. Delete row from file
2. Delete columns from file
Select your choice [1 or 2]?
1
./test-array: line 14: syntax error near unexpected token `do'
./test-array: line 14: `        do '
smitra:Desktop smitra$

And further I am having a problem to name the modified file as (Input)_modified.
Any help will be really great.
Thanks
# 4  
Quote:
Originally Posted by smitra
this is the output so far...

Code:
1. Delete row from file
2. Delete columns from file
Select your choice [1 or 2]?
1
./test-array: line 14: syntax error near unexpected token `do'
./test-array: line 14: `        do '
smitra:Desktop smitra$

And further I am having a problem to name the modified file as (Input)_modified.
Any help will be really great.
Thanks

as of now i found below issues, please check..

if [ $osch -eq 1 ]; #Space is needed in square brackets for first and second if.

#in first if there is no for loop ahead of do

for i in # i think you are checking for the areray elements .. add to the in..
# 5  
Hi Pamu,
Thank for the reply. I tried to put space in the square bracket. But still the same problem And I am not sure how to fix the loop. Smilie

Code:
osch=0
echo "1. Delete row from file"
echo "2. Delete columns from file"
echo "Select your choice [1 or 2]?"
read osch
if [ $osch -eq 1 ]; 
then
        echo "Enter row numbers with space"
        read x
        echo 'You entered this line: ' $x
        set -A rarray $x
        do 
                awk 'NR!={rarray[@]}' INPUT > INPUT_modified
        done
        echo "Modified file is created"
fi

if [ $osch -eq 2 ]; 
then
        echo "Enter column numbers with space"
	read y
        echo 'You entered this line: ' $y
	set -A rarray $y
        do 
	     awk '{for(i=1;i<=NF;i++)if(i!={rarray[@]})printf '%s', $i OFS;print""}' INPUT > INPUT_modified
        done
        echo "Modified file is created"
fi

Here are the same error again:
Code:
1. Delete row from file
2. Delete columns from file
Select your choice [1 or 2]?
1
./test-array: line 14: syntax error near unexpected token `do'
./test-array: line 14: `        do '

Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #575
Difficulty: Medium
If a program has poor memory management and fails to deallocate memory when it is no longer needed, the memory will not leak.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Making any script executable

Hi all, I'm new to Unix so just wanted some help. I've been self learning and came accross a question online that I was trying. It is to make any shell script executable, the name of the file is to be made executable. I would use nano and type in something like #! /bin/bash Chmod +x... (4 Replies)
Discussion started by: HelenaR
4 Replies

2. OS X (Apple)

Creating An Executable On The Fly...

Hi all... Had an idea tonight which could really enhance shell scripting for me. Yes I am aware there could be difficulties but...... Creating a C script inside the shell script to do a task, (a simple text print to stdout in this example), compiling it on the fly, making sure it is... (4 Replies)
Discussion started by: wisecracker
4 Replies

3. Shell Programming and Scripting

How to produce a executable Oracle script from bash script?

Hi here's my code ${ORACLE_HOME}/bin/sqlplus /nolog <<!EOF --step 5 create db script start set feedback off set heading off set echo off conn / as sysdba spool ${ORACLE_SID}_db_link.sql SELECT 'CREATE '||DECODE(U.NAME,'PUBLIC','public ')||'DATABASE LINK '||CHR(10)... (2 Replies)
Discussion started by: jediwannabe
2 Replies

4. UNIX Desktop Questions & Answers

creating an executable file from shell scripts

Hi Friends, I have a shell script which does some operations etc, would it be possible to create an executable file out from this shell script? meaning the executable file is not editable, thus the source code will not be visible to other users for copyright reasons. Please help, thanks! (1 Reply)
Discussion started by: kokoro
1 Replies

5. Shell Programming and Scripting

Unable to call executable from script

Now I am using the HP-UX11.11 version. The scripts are runninh in KSH shell. While I wan to call one executable of any Pro*C file, I have got the following error, however the executable is running fine directly. testpri Started at 10.05.200923:40 /usr/lib/dld.sl: Bad magic number for... (0 Replies)
Discussion started by: priyankak
0 Replies

6. Shell Programming and Scripting

help needed with creating challenging bash script with creating directories

Hi, Can someone help me with creating a bash shell script. I need to create a script that gets a positive number n as an argument. The script must create n directories in the current directory with names like map_1, map_2 etcetera. Each directory must be contained within its predecessor. So... (7 Replies)
Discussion started by: I-1
7 Replies

7. UNIX for Dummies Questions & Answers

need help making a script executable

making a script in vi to create a shell script called wherearethey by entering the following script: echo -n "Who are you looking for: "read userif then list=`w | grep $user | cut -c19-30` if then echo "The user $user is logged in from $list" else echo "The user $user is not logged in... (3 Replies)
Discussion started by: curtner
3 Replies

8. OS X (Apple)

What's The Easiest Route To Creating A Unix Executable File for Terminal?

I've seen the executable open in the application OmniOutliner, can I create an executable with this app? I'd like to be able to create the unix executable and insert it into terminal, but I'm not sure if the Omni app will allow me to create it. Any one have any ideas or possibly familiar with... (10 Replies)
Discussion started by: unimachead
10 Replies

9. UNIX for Dummies Questions & Answers

creating executable for every C file

hello Folks, once we compile any C code on Linux, we run the code using "./a.out".. but can we have an executable for every program so that we can run the code directly without compiling the code every time. just run the executable and get the output! Thanks! (7 Replies)
Discussion started by: compbug
7 Replies

10. Programming

problem in creating executable for a client program

Hi, I am trying to run simple client server c program in unix.At the compling stage server is creating an executable but the client is not. below is the link to the source codes: http://www.cs.rpi.edu/courses/sysprog/sockets/server.c http://www.cs.rpi.edu/courses/sysprog/sockets/client.c ... (2 Replies)
Discussion started by: konas
2 Replies

Featured Tech Videos