Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
7  
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
add comment

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.

2 Answers

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

#!/bin/bash
echo $1
while read STRING
do
    echo $STRING
done

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

#!/bin/bash
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
add comment

In your process_data.sh you can write below code

while read line
do
   #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
add comment

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