Dividing a column and submitting it as stdin


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Dividing a column and submitting it as stdin
# 1  
Old 04-01-2015
Dividing a column and submitting it as stdin

I currently have two programs written in C named "remove" and "calculate.

When I call ./remove it removes some data from stdin.
When I call ./calculate which takes in an argument and also data from stdin and calculates and returns a value.

Currently writing a script that calls both of these programs.

I call my script with the following:

Code:
    ./calc.sh input.txt 2 3 4 5

where "2 3 4 5" are arguments and input.txt has:

Code:
    abcd:1,2:3,4
    efgh:5,4:4,4
    hijk:3,1:4,9

Running the remove program returns

Code:
    abcd:1,2:3,4
    efgh:5,4:4,4

The format I would like it in:

Code:
   1 2 3 4
   5 4 4 4

My script is currently:

Code:
    ./remove "$1" | ./calculate "$1" "$2" "$3" "$4" < awk -F ':,' '

How do I fix the script so that I select the columns of integers from input.txt and switch them into my desired form and submit it into ./calculate as stdin along with "2 3 4 5" with arguments?

Last edited by Don Cragun; 04-01-2015 at 02:08 AM.. Reason: Add CODE and ICODE tags.
# 2  
Old 04-01-2015
Please use CODE tags when showing sample input, output, and code in your posts.

I'm not sure I understand what you're trying to do, but it seems like something like this would come close to doing what you want. This does not care if there are leading spaces in the output from remove and will only put one leading space in the data it feeds into calculate. If you really want four leading spaces in the output from the awk code, I'll leave that as an exercise for the reader:
Code:
file="$1"
shift
./remove "$file" | awk -F'[,:]' '{$1="";print}' OFS=' ' - | ./calculate "$@"

Note that this will work with any number of fields in the output from remove (just removing the 1st field from the output) instead of assuming that there will be five fields in the input and four fields in the output. And, it will pass zero or more operands from the calc.sh command line to calculate rather than the fixed four arguments you seem to be assuming. If you want to verify that calc.sh is called with exactly five operands, I will leave that as an exercise for the reader.

You haven't said what operating system or shell you're using. This makes the wild assumption that you're using a shell that recognizes Bourne shell syntax.

And, if you want to try this on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Dividing a column by it's last number

Hi! I have a file as below: 0.000145 5.82056e-08 0.000146 6.82088e-08 0.000150 7.42115e-08 0.000156 8.52142e-08 0.000176 8.82169e-08 0.000178 9.82197e-08 I'd like to divide the values of the second column by its last entry (here 9.82197e-08). I would be thankful if someone could... (6 Replies)
Discussion started by: Setareh12
6 Replies

2. UNIX for Advanced & Expert Users

Submitting multiple qsub jobs

Hi all, Today, I want to ask how to submit multiple qsub jobs. I want to submit 100 .sh files for the simulations. The name of files is run_001.sh, run_002.sh, run_003.sh, ..... ..... run_100.sh Submitting each file manually are time-consuming, hence, I want to make another .sh file... (11 Replies)
Discussion started by: syg3434
11 Replies

3. UNIX for Dummies Questions & Answers

Submitting cron job through script

I would like to run a script, as root, which will eventually set up cron job for a non privilege user. Please advice. (9 Replies)
Discussion started by: atanubanerji
9 Replies

4. UNIX for Dummies Questions & Answers

Dividing a column by it's first number

Hi! Is there an easy way (maybe using awk??) to divide the values of one column of the file by it's first entry.. If I have a column: 3 4 5 6 7 I would like to divide it by 3. I want to do this for more than 100 files, so it wouldn't be practical to open file by file and... (26 Replies)
Discussion started by: cosmologist
26 Replies

5. Shell Programming and Scripting

Help submitting jobs to cluster

Hi I am new to submitting jobs. I am trying to submit my perl file to the cluster. This is what my shell file looks like (shell1.sh): #!/bin/sh #$ -S /bin/sh cd data/projects/mydir/abbc perl autocorro.pl followed by qsub shell1.sh It takes the qsub, but does nothing. I check... (1 Reply)
Discussion started by: theawknewbie
1 Replies

6. UNIX for Dummies Questions & Answers

problem submitting job to queue

Hi, I am trying to submit a job to a queue on a cluster. When I run the job ( python script) from the command line it runs without putting python at the start. The script imports everything from another congifuration file (.config) but when I submit to the queue it tells me there is no module... (0 Replies)
Discussion started by: i-dont-know
0 Replies

7. HP-UX

Sendmail not submitting Email on '.'

I have several HP/UX nodes running Sendmail 8.13 ...some work fine, some don't. When an Email is coming in, the 'DATA' command never ends. The other side of the connection gets to the point where it enters the '.' on a line by itself, but sendmail doesn't accept it...if fact it keeps on holding... (8 Replies)
Discussion started by: john_exonets
8 Replies

8. UNIX for Dummies Questions & Answers

How to use parameters in command line while submitting a report

Iam running a report(.rdf) file from UNIX command line. using the following syntax for eg xxx.rdf is the report rdf ar60run batch=yes userid=username/paswd@database report=xxx.rdf destype=file desname=xxx.dat now i need to submit this with three pameters pls suggest (1 Reply)
Discussion started by: sreenusola
1 Replies

9. Shell Programming and Scripting

submitting data during a program run

I'm new to this and didn't know what my problem is called but here it is: A program called "prepdata" is run which asks the user to enter in a <input> file for the data to be taken from. However, it won't accept that input filename as an argument: $ prepdata <input> will NOT work ... (2 Replies)
Discussion started by: Rob W
2 Replies

10. UNIX for Advanced & Expert Users

Submitting jobs remotely...Experts help reqd

Is there any way I can submit a job to a remote machine and return immediately without withing for the job to finish? What I mean is this...using rsh I can submit a job to a remote machine like this: rsh remotemac1 job.sh But this doesn't return untill the job has finished and as a... (3 Replies)
Discussion started by: arijit
3 Replies
Login or Register to Ask a Question