Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
Problem is like that
I have to write a shell script. Script will get many arguments. first is file name and the others are strings which script search them in a file.
for example my file name is shell.txt and it contains
"I have to write a shell script.
Script will get many arguments. first is
file name and the others are strings
which script search them in file."
./search shell.txt script strings and first
then results must bu like that:
script 3 times at lines 1,2,4
strings 1 time at line 2
and 1 time at line 3
first 1 time at line 2
i am new to shell programming. i search a bit and i decide grep command may help me but i think its useful to ask my questions to experts. is shell scripting have capability reading and writing files like c. open a file for reading and then getting chars etc...
or i have to use linux commands like grep to solve this problem.
help me a bit. which commands do i have to insist on.
Originally posted by marghorp Smells like homework to me
Well if thats right, then it's one hell of a home work topic. When I was at school, that kind of stuff was left up to the post graduate "pin striped nazis" in big corporations in those spooky looking 70's pictures of mega main frame systems
Originally posted by qerf yes it is true, it is homework but i dont want to complete solution. Only tips pls...
In that case, grep is not what you want. Neither is cat or sed. What you want is the read command:
read [-ers] [-u fd] [-t timeout] [-a aname] [-p prompt] [-n nchars] [-d
delim] [name ...]
One line is read from the standard input, or from the file
descriptor fd supplied as an argument to the -u option, and the
first word is assigned to the first name, the second word to the
second name, and so on, with leftover words and their interven-
ing separators assigned to the last name. If there are fewer
words read from the input stream than names, the remaining names
are assigned empty values. The characters in IFS are used to
split the line into words. The backslash character (\) may be
used to remove any special meaning for the next character read
and for line continuation. Options, if supplied, have the fol-
The words are assigned to sequential indices of the array
variable aname, starting at 0. aname is unset before any
new values are assigned. Other name arguments are
The first character of delim is used to terminate the
input line, rather than newline.
-e If the standard input is coming from a terminal, readline
(see READLINE above) is used to obtain the line.
read returns after reading nchars characters rather than
waiting for a complete line of input.
Display prompt on standard error, without a trailing new-
line, before attempting to read any input. The prompt is
displayed only if input is coming from a terminal.
-r Backslash does not act as an escape character. The back-
slash is considered to be part of the line. In particu-
lar, a backslash-newline pair may not be used as a line
-s Silent mode. If input is coming from a terminal, charac-
ters are not echoed.
Cause read to time out and return failure if a complete
line of input is not read within timeout seconds. This
option has no effect if read is not reading input from
the terminal or a pipe.
-u fd Read input from file descriptor fd.
If no names are supplied, the line read is assigned to the vari-
able REPLY. The return code is zero, unless end-of-file is
encountered, read times out, or an invalid file descriptor is
supplied as the argument to -u.
As well as using a while loop:
while read line ; do
done < file
Of course, you still have to break up the variable line into smaller parts which is left as an excercise to you (hint: only requires a for-loop).
thank you blindcoder. as i said my problem is that i am not familiar to linux so i dont know which command i have to use. i can only find grep but no clue about read. so
i will insist on read. i can handle syntax solution logic and others thank you again. i only need a bit technical support.
can anybody suggest me bash tutorials book or web page
Distribution: Debian Etch (w/ dual-boot XP for gaming)
And, as always, I'll recommend the Linux Documentation Project as an excellent source of info - particularly their books on Bash (both available from the guides page, along with much other useful info).