read from a file
3 posters
read from a file
To read from stdin we use
read line
how do i read the contents of a file(passed as an argument to script) line by line....
read line
how do i read the contents of a file(passed as an argument to script) line by line....
akalya- Posts : 70
Points : 86
Join date : 2010-03-04
Re: read from a file
ok got it!!!
cat linenos | while read line
do
echo $line
done
linenos is the filename!!
cat linenos | while read line
do
echo $line
done
linenos is the filename!!
Last edited by akalya on Mon Mar 08, 2010 6:37 pm; edited 1 time in total
akalya- Posts : 70
Points : 86
Join date : 2010-03-04
Re: read from a file
create the input file as c.txt
ur script file will be
#!/bin/bash
clear
cat $1 | while read line
do
echo $line
done
and exec it as: sh <filename>.sh c.txt
I think this is what u asked for..
ur script file will be
#!/bin/bash
clear
cat $1 | while read line
do
echo $line
done
and exec it as: sh <filename>.sh c.txt
I think this is what u asked for..
Saradha Kannan- Posts : 25
Points : 25
Join date : 2010-03-04
Re: read from a file
n=`wc -l < $1`
i=1
while [ "$i" -le "$n" ]
do
line=`cat $1 | head -$i | tail -1`
echo $line
i=`expr $i + 1`
done
This is a small script which reads line by line and prints it.
i=1
while [ "$i" -le "$n" ]
do
line=`cat $1 | head -$i | tail -1`
echo $line
i=`expr $i + 1`
done
This is a small script which reads line by line and prints it.
Maithreyi- Posts : 76
Points : 142
Join date : 2010-03-03
Age : 36
Location : Haldia
Re: read from a file
even this work:
while read line
do
echo $line
done < $1
where $1 is the name of the file to be read
while read line
do
echo $line
done < $1
where $1 is the name of the file to be read
akalya- Posts : 70
Points : 86
Join date : 2010-03-04
Re: read from a file
@ akalya ! ya it does. I posted my message before seeing that !
Maithreyi- Posts : 76
Points : 142
Join date : 2010-03-03
Age : 36
Location : Haldia
Similar topics
» exact file search?
» Change Owner of a File
» deleting a particular line in a file
» header file is not getting recognised (in Eclipse/C++)
» copying file contents across directories
» Change Owner of a File
» deleting a particular line in a file
» header file is not getting recognised (in Eclipse/C++)
» copying file contents across directories
Permissions in this forum:
You cannot reply to topics in this forum