Solved

shell script to reads lines of a file ?

Posted on 2007-11-16
2
522 Views
Last Modified: 2013-12-26
The following script should read lines of the input file, but just
returns the file name. How do I get it to read the lines of the file,
one at a time ?

#! /bin/csh

set f = $1

foreach d ( $f  )

echo  $d

end
0
Comment
Question by:pillmill
2 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 20303009
#!/bin/bash
f=$1
while read d ; do
  echo  $d
done < $f
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 500 total points
ID: 20303812
(t)csh has no command to read files line by line 'cause there're countless other tools (awk, sed, perl, ...) which do it in a better way
Either switch to sh (or friends like bash) as ozo suggested
or use something like:
  foreach d ("`cat $f`")
    echo $d
  end
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now