Shell Script - File Input/Output in C


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Script - File Input/Output in C
# 1  
Old 11-27-2012
Shell Script - File Input/Output in C

This is part of my code:

Code:
       
 for in_file in $1/*.in    # list of all .in files in working directory.    
 do                
     $c_file < $in_file > "$tempFile.out"             
      if  diff "$tempFile.out" $out_file  >/dev/null 2>&1 ;            
      then               
          echo "corresponding files are the same!"           
     else                 
          echo "different!"           
    fi 
done

$c_file is a C program, $in_file is an input file. "$tempFile.out" doesn't work.... I don't think the output file was created.



This code is inside a for loop, and for each loop, there is a different input file. A file is created after the first loop, but "$tempFile.out" isn't overridden for the next loops. So, for diff, it's comparing "$tempFile.out" with $out_file for each loop.
I want the output of $c_file < $in_file to override "$tempFile.out" for each loop.
Any ideas?

Last edited by spider-man; 11-27-2012 at 02:46 AM..
# 2  
Old 11-27-2012
You can try like this,

Code:
 for in_file in $1/*.in    # list of all .in files in working directory.    
 do
 $c_file < $in_file >> $tempFile.out
  if  diff "$tempFile.out" $out_file  >/dev/null 2>&1 ;            
   then               
  echo "corresponding files are the same!"           
  else                 
echo "different!"           
  fi done

# 3  
Old 11-27-2012
I changed to code to what you wrote.

it's actually created a new file called ".out"

It doesn't seems to be overriding the .out
It seems like it's adding more inputs to the .out file for each loop.

Is there a simpler way of doing this?
# 4  
Old 11-27-2012
I don't see a variable tempFile defined anywhere!!

I think you have to remove the "$" sign in that, so that it would write in a file named tempFile.out

What are the extra inputs that were added to this out file???
# 5  
Old 11-27-2012
yup, it created tempFile.out

Let me give you an example:
I have two .in files
Code:
%cat hi.in
abc

%cat bye.in
def

the tempfile will end up containing:
abcdef
after two loops.

It seems like it's gathering up the inputs in the tempfile.
# 6  
Old 11-27-2012
I am sorry, I couldn't understand this issue here Smilie
# 7  
Old 11-27-2012
nvm, it works now. lol

I changed
Code:
$c_file < $in_file >> tempFile.out

back to
Code:
$c_file < $in_file > tempFile.out

It works!!!

Last edited by Scott; 11-27-2012 at 03:28 AM.. Reason: Code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Python or Shell script to Grep strings from input file and output in csv format

Hi Experts, I am writing a python script to grep string from file and display output in csv file as in attached screenshot https://drive.google.com/file/d/1gfUUdfmQma33tz65NskThYDhkZUGQO0H/view Input file(result_EPFT_config_device) Below is the python script i have prepared as of... (1 Reply)
Discussion started by: as7951
1 Replies

2. UNIX for Beginners Questions & Answers

Need list of input and output parameter of task in a text file, using shell script

//file begin ===== //some code task abcd_; input x; input y,z; //some comment output w; //some comment reg p; integer q; begin //some code end endtask : abcd_ //some code //file end ===== expected output from above... (1 Reply)
Discussion started by: rishifrnds
1 Replies

3. Shell Programming and Scripting

adding data in input file if 2nd script output SUCCESS

Hi All, how can i edit my original data and add more data if my 2nd script outputs SUCESS? ex. input file: 1.txt nik,is,the 1script.sh if 2ndscript.sh output SUCCESS then i'm going to edit my input file and add data best,pogi.. sample outputdata. nik,is,the,best,pogi 2ndscript.sh... (3 Replies)
Discussion started by: nikki1200
3 Replies

4. Shell Programming and Scripting

generate tabular output from an input text file in unix shell scripting

Hi, I have the output (as below) which i want it to be in a table. For e.g. space utilization in PSE on path /logs is 0% space utilization in PSE on path /logs/tuxedo/tuxlsp is 16% space utilization in PSE on path /ldvarlsp/lsp/log is 37% space utilization in PSE on path /home is 6%... (7 Replies)
Discussion started by: pkbond
7 Replies

5. Shell Programming and Scripting

AWK Script to convert input file(s) to output file

Hi All, I am hoping someone can help me with some scripting I need to complete using AWK. I'm trying to process multiple fixed files to generate one concatenated fixed file in a standard format. The Input file is:- aaaa bbbbb ccccc 1 xxxx aaa bbb aaaa bbbbb ccccc 2 abcd aaa CCC... (9 Replies)
Discussion started by: jason_v_brown
9 Replies

6. Shell Programming and Scripting

Dynamic output file generation using a input text file with predefined output format

Hi, I have two files , one file with data file with attributes that need to be sent to another file to generate a predefined format. Example: File.txt AP|{SSHA}VEEg42CNCghUnGhCVg== APVG3|{SSHA}XK|"password" AP3|{SSHA}XK|"This is test" .... etc --------- test.sh has... (1 Reply)
Discussion started by: hudson03051nh
1 Replies

7. Programming

Redirect input and output to a shell script?

Dear All: I am trying to do something that (I thought) was relatively straightforward, but my code snippet does not seem to work. Any suggestions? Thank you Sincerely yours Misha Koshelev #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <errno.h> #include... (0 Replies)
Discussion started by: misha680
0 Replies

8. Shell Programming and Scripting

Pass input and output file as parameter to awk script

Hi, i am new to awk. I am using csv2pipe script(shown below) BEGIN { FS=SUBSEP; OFS="|" } { result = setcsv($0, ",") print } # setcsv(str, sep) - parse CSV (MS specification) input # str, the string to be parsed. (Most likely $0.) # sep, the separator between the values. # #... (6 Replies)
Discussion started by: bhaskarjha178
6 Replies

9. Shell Programming and Scripting

Shell script getting input from output

I have a program that can be run in terminal, when its run it either returns SSH OK or CRITICAL, how do i use the output in my script? good ./check_sh myserver SSH OK bad ./check_sh myserver CRITICAL I want to store it in a variable btw, SSH OK will give the variable $SSH=1 and if its... (1 Reply)
Discussion started by: aspect_p
1 Replies

10. Shell Programming and Scripting

Asking about shell script input output redirection

Hi, Can anyone please tell me what these lines do? ls >& outfile ls outfile 2>&1 Thanks. (1 Reply)
Discussion started by: trivektor
1 Replies
Login or Register to Ask a Question