Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to read input from a file given in following format.

$ ./process_data.sh arg1 < input_data.txt

How do I read input_data in my shell script process_data.sh?

share|improve this question

closed as not a real question by jw013, jasonwryan, Renan, warl0ck, Stéphane Gimenez Sep 17 '12 at 19:31

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

The question is much too vague. Read Bash FAQ 01 about processing lines from input and come back when you have a specific question. – jw013 Apr 17 '12 at 7:59

In such usage there are several ways to read it: while construction (will output argument and each string of file input_data.txt)

echo $1
while read STRING
    echo $STRING

awk (will output argument and second and third column of file input data)

echo $1
awk '{print $2" "$3}'

and so on. You can use sed, cut and many other unix utilities like in examples. Chose of utility depends on how you need to transform input data. Of course you can change examples as you want.

Good luck =)

share|improve this answer

In your process_data.sh you can write below code

while read line
   #work on data
done < `cat input_data.txt`
share|improve this answer
Have you even tried this? – Stéphane Gimenez Sep 17 '12 at 19:31

Not the answer you're looking for? Browse other questions tagged or ask your own question.