Simple Bash Read File question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Simple Bash Read File question
# 1  
Old 06-08-2007
Simple Bash Read File question

Hello all,

I am trying to write a simple script that will parse through a text/properties file and check a couple of if statements.

Here is what I have so far:

FILENAME=$1
while read line
do
echo $line
done < $FILENAME

When I call ./simple.sh testfile.txt I recieve a file or directory cannot be found.. I know it is something increadibly simple that I am missing.

Thanks,
Lammy
# 2  
Old 06-08-2007
post deleted
# 3  
Old 06-08-2007
See what happens when you do the following:
Code:
ls -l ./simple.sh
ls -l testfile.txt

# 4  
Old 06-08-2007
bash is correct, you don't have such file. Example :
I will create file called "test.txt" with "test123" string in it.
your script will look like this :
Code:
FILENAME=$1
while read line
do echo test
echo $line
done < $FILENAME

and run :
Quote:
[sysgate@myserver ~]$ ./test.bash test.txt
test
test123
# 5  
Old 06-08-2007
All,

If I do an ls -l both files are in the same directory.

Here is what I do to run my simple.sh

./simple.sh test[Tab Complete]

which gives me
./simple.sh test.txt

if I can tab complete it.. i believe it is in the same directory.

I put in the followin code

Code:
FILENAME=$1
while read line
do echo test
echo $line
done < $FILENAME

output was
./simple.sh: line 19: test.txt: No such file or directory


All really good suggestions but I think that there might be something else a miss on this extremely simple script...
# 6  
Old 06-08-2007
Lamagra,
As you can see in the error message, the shell is pointing to
line number 19.
Why don't you display the entire script?
# 7  
Old 06-08-2007
You know shell thats a really good idea..

Sorry all I guess it would have been a little more beneficial if I would have done that the first.

Code:
#!/bin/bash

cd /test/me/i/am/a/noob/ie

#COUNTER=0
#while [ $COUNTER -lt 2 ]; do
command that lives in IE directory
#done





FILENAME=$1
while read line
 do
  echo test
  #echo $line
done < $FILENAME


I see the problem now that I have pasted it in here. Because i do a cd to be able to run the command that lives in the ie directory. Doing this changes where I am pointing to and would not recognize the test.txt file.

How do I use the command in ie (directory) without cding?

Can I set it to a variable such as:

Code:
COMMAND_PATH=/test/me/i/am/a/noob/ie
$COMMAND_PATH/COMMAND ARGS

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Syslog.conf: looking for a simple answer on a simple question

Cheers! In /etc/syslog.conf, if an error type is not specified, is it logged anywhere (most preferable is it logged to /var/log/messages) or not? To be more precise I am interested in error and critical level messages. At default these errors are not specified in syslog.conf, and I need to... (6 Replies)
Discussion started by: dr1zzt3r
6 Replies

2. Homework & Coursework Questions

Shell Script to read a tab delimited file and perform simple tasks

1. The problem statement, all variables and given/known data: Hello! I need help with this problem bash shell scripting that basically just reads the data in a tab delimited file and does the following below 1. Read in the data file Survey.txt and assign the column values to variables of... (6 Replies)
Discussion started by: jsmith6932
6 Replies

3. Homework & Coursework Questions

Create a simple bash backup script of a file

This is the problem: Write a script that will make a backup of a file giving it a ‘.bak’ extension & verify that it works. I have tried a number of different scripts that haven't worked and I haven't seen anything really concise and to the point via google. For brevity's sake this is one of the... (4 Replies)
Discussion started by: demet8
4 Replies

4. Shell Programming and Scripting

Help making simple perl or bash script to create a simple matrix

Hello all! This is my first post and I'm very new to programming. I would like help creating a simple perl or bash script that I will be using in my work as a junior bioinformatician. Essentially, I would like to take a tab-delimted or .csv text with 3 columns and write them to a "3D" matrix: ... (16 Replies)
Discussion started by: torchij
16 Replies

5. Shell Programming and Scripting

Simple Question about Reading file by Perl

Hi , I just write a simple function to read the file line by line. But when I run it it says out of memory. I am not sure about the root cause, Can someone help me out of this? :D #! /usr/bin/perl use strict; sub checkAPs{ my $NDPDir = "/home/eweiqqu/NCB/NDP_files/"; ... (1 Reply)
Discussion started by: Damon_Qu
1 Replies

6. Shell Programming and Scripting

Simple while read line loop question

#!/bin/bash count=1 while read line do if (($count > 4)); then awk -v var1="$count" '{printf "%3s%8s%11s%11s%11s\n",var1,$2,$3,$4,$5}' else echo $line fi count=$((count+1)) done < posre_sub.itp > test cat test INPUT: ; position restraints for... (3 Replies)
Discussion started by: origamisven
3 Replies

7. UNIX for Dummies Questions & Answers

Simple question on unix file permission

As I understand the file permissions in UNIX is basically Owner, group, others Lets assume scott user who's primary group is dev creates a file called test.dat and then grants some privileges on that file... scott@unix-host> echo "this is a test" > test.dat scott@unix-host> chmod 640... (4 Replies)
Discussion started by: luft
4 Replies

8. UNIX for Dummies Questions & Answers

Question on how to manipulate a SIMPLE text file (using awk?)

I have a simple txt files that looks something like this (The title is a part of the text file) Student Grades --------------- 1 Tim Purser 89 2 John Wayne 56 3 Jenn Hawkins 95 4 Harry Potter 75 Here are my questions: How would I ONLY print the names of students... (2 Replies)
Discussion started by: ninjagod123
2 Replies

9. Shell Programming and Scripting

Simple bash question - 2 files together

Hello Friends, I have a simple problem but I can't seem to find a solution, perhaps you could gimme a hand here.. I have to files 1.txt which contains the following 00 01 02 03 and 2.txt which contains the following: 20 21 22 23 All I need is to concatenate these 2 files in... (2 Replies)
Discussion started by: bashshadow1979
2 Replies

10. Shell Programming and Scripting

dead simple bash script question

I need help writing a bash script that will simply prompt the user with a list of choices, then run an action based on the input. The action is running a wake-on-lan app called etherwake and passing a pre-defined mac address to the syntax. I have defined the three MAC addresses as: MAC1, MAC2,... (12 Replies)
Discussion started by: graysky
12 Replies
Login or Register to Ask a Question