How to get the shell script to read the .txt file as an input/data?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to get the shell script to read the .txt file as an input/data?
# 8  
Old 05-04-2017
There is exactly one while read in your script. That's where it belongs.

The ... is the stuff inside the loop.

The 'done' at the end of the loop is something your script is missing right now and won't work without.

Last edited by Corona688; 05-04-2017 at 04:15 PM.. Reason: do/done
# 9  
Old 05-04-2017
Basically, what you have already:

Code:
while read variablename
do
...
done

What you need:

Code:
while read variablename
do
...
done < inputfile

# 10  
Old 05-04-2017
Ah I seem to understand, I will get back to you if I run into any issues

---------- Post updated at 09:18 PM ---------- Previous update was at 08:19 PM ----------

Quote:
Originally Posted by Corona688
In the shell.

Code:
while read file
do
...
done < inputfile

Write it inside the shell using any UNIX text editor you like. nano, pico, vi, emacs... Whichever you happen to have.
what exactly would i write in the shell for the input file. The text in the input file is :
i n p u t . t x t
add $s0 $s1 $s2
sub $s2 $t0 $t3
add $s0 $s1 $z2
lw $t1 8($t2)

addi $t3 $s0 −9
sw $s3 4($t0)
lw $t11 70000($s0)

how would i type this in the shell to be the input file that is to be read?
# 11  
Old 05-04-2017
Probably something along the lines of

Code:
nano filename

add $s0 $s1 $s2
sub $s2 $t0 $t3
add $s0 $s1 $z2
lw $t1 8($t2)

addi $t3 $s0 −9
sw $s3 4($t0)
lw $t11 70000($s0)

control-W
enter
control-X

If you really have no editor whatsoever - get one ASAP - you can cheat with

Code:
cat > input.txt <<EOF
addi $t3 $s0 −9
sw $s3 4($t0)
lw $t11 70000($s0)

addi $t3 $s0 −9
sw $s3 4($t0)
lw $t11 70000($s0)
EOF

# 12  
Old 05-05-2017
The "ASAP method" needs to avoid the shell's $var expansions.
Put the EOF in quotes!
Code:
cat > input.txt <<"_EOF_"
addi $t3 $s0 ?9
sw $s3 4($t0)
lw $t11 70000($s0)

addi $t3 $s0 ?9
sw $s3 4($t0)
lw $t11 70000($s0)
_EOF_

Still the shell might do some substititions. A safe method is to read from the Unix/Linux terminal input (at the shell prompt)
Code:
cat > input.txt

and paste the text/code into it, then hit Control-D to close the input.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk, sed, shell all words in INPUT.txt find in column1 of TABLE.txt and replce with column2 in

Hi dears i have text file like this: INPUT.txt 001_1_173 j nuh ]az 001_1_174 j ]esma. nuh ]/.xori . . . and have another text like this TABLE.txt j j nuh word1... (6 Replies)
Discussion started by: alii
6 Replies

2. Programming

Writing a UNIX shell script to call a C function and redirecting data to a .txt file

Hi, I am complete new to C programming and shell scripting. I just wrote a simple C code to calculate integral using trapezoid rule. I am prompting user to pass me No. of equally spaced points , N , upper and lower limit. My code looks as follows so far: #include<stdio.h> #include<string.h>... (2 Replies)
Discussion started by: bjhjh
2 Replies

3. UNIX for Dummies Questions & Answers

Inserting shell script input data automatically from a text file

Dear experts, I am new to linux programming. I have a shell script which i should run it on all my samples. I only define input and out put for this script. The inputs are 3 numbers(coordination numbers) which are available in a series of text file. Since i have a lots of samples, it takes a... (5 Replies)
Discussion started by: mohamadreza
5 Replies

4. UNIX for Dummies Questions & Answers

Shell script to read lines in a text file and filter user data Shell Programming and Scripting

sxsaaas (3 Replies)
Discussion started by: VikrantD
3 Replies

5. Shell Programming and Scripting

Needed shell script to read txt file and do some modification

Hi ...programmers... I need a shell script to perform some specific task.. my txt file looks like this netcdf new { dimensions: XAX1_11 = 11 ; variables: double XAX1_11(XAX1_11) ; XAX1_11:point_spacing = "even" ; XAX1_11:axis = "X" ; float DEPTH(XAX1_11) ;... (19 Replies)
Discussion started by: Akshay Hegde
19 Replies

6. Shell Programming and Scripting

Want to read data from a file name.txt and search it in another file and then matching...

Hi Frnds... I have an input file name.txt and another file named as source.. name.txt is having only one column and source is having around 25 columns...i need to read from name.txt line by line and search it in source file and then save the result in results file.. I have a rough idea about the... (15 Replies)
Discussion started by: ektubbe
15 Replies

7. Shell Programming and Scripting

shellscript to read data from txt file and import to oracle db

Hi all, Help needed urgently. I am currently writing a shellscript to read data/record from a flat file (.txt) file, and import/upload the data to oracle database. The script is working fine, but it takes too long time (for 18000 records, it takes around 90 mins). I guess it takes so long... (1 Reply)
Discussion started by: robot_mas
1 Replies

8. Shell Programming and Scripting

The scope of the shell/perl script is to read the input text file. Validate the expiry date of each

The scope of the shell/perl script is to read the input text file. Validate the expiry date of each certificate and send the mail to the user. The user takes action to add the new certificate to the storage file and user owns the responsibility to update the input text file with the new certificate... (5 Replies)
Discussion started by: casmo
5 Replies

9. Shell Programming and Scripting

Read data from .csv file through shell script & modify

I need to read data from a file called "test.csv" through shell script where the file contains values like name,price,descriptor etc. There are rows where descriptor (& in some rows name) are written as string & other characters like "car_+" OR "bike*" etc where it should contains strings like... (3 Replies)
Discussion started by: raj100
3 Replies

10. Shell Programming and Scripting

How to read the data from the text file in shell script?

I am having one text file and i need to read that data from my shell script. I will expain you the scenario: Script look like: For name type 1: For age type 2: For Salary type3: echo "Enter the input:" read the data if input is 1 then go to the Text file and print the... (2 Replies)
Discussion started by: dineshmurs
2 Replies
Login or Register to Ask a Question