Re: Read a file line by line in c shell script
2007-05-10, 06:46(-07), [email]firstname.lastname@example.org[/email]:[color=blue]
> i am new to shell scripting &
> I wanna read a file line by line in a c shell script and execute some
> command for each data in a line and have to get the out put for a log
> how I can do this looping process?[/color]
The C shell is not for scripting. One generally writes scripts
in a standard sh syntax that is a syntax recognised by most
modern Bourne-like shells (bash, ksh, pdksh, ash... at least
when called as "sh"), it's a lot better suited for scripting and
it that kind of approach helps greatly when you want to port
your script from one system to another.
A shell is a tool to call other tools. Most if not all the
standard text processing tools (cut, sed, awk, paste...) read
files line by line (have a builtin loop if you want, though you
shouldn't think in terms of loops in shells).
What exactly do you want to achieve?
For instance, if you want do take the 10th to 20th character of
each line of your log file, and convert all the letters to
uppercase, you'd do something like:
< logfile.in cut -c10-20 | tr '[:lower:]' '[:upper:]' > logfile.out
If you want to do more complicated than what the simple one-task
tools (head, tail, cut, paste, tr...) when combined together,
you'll have to use more complex tools such as sed or awk.
You may then find that using perl will make your life a lot
easier, and then you can even drop the shell or only use it only
as a wrapper to call perl and feed it its input and get the