0

I have severial variables with prefix INPUT:

${INPUT_1:="sample.txt"}
${INPUT_2:="sample_2.txt"}
${INPUT_3:="sample_3.txt"}

And then I get a list of variable value with prefix INPUT by :

env | awk -F= '/^INPUT/ {print $2}'

the result:

sample.txt sample_2.txt sample_3.txt

And then I want to count the lines of each these three file, I tried

 var = env | awk -F= '/^INPUT/ {print $2}'
 wc -l $var

But it didn' work. Does someone could help me with applying wc -l on the variables selected?

2
  • shellcheck.net . but also research xargs, many, many Q/A here for that topic. Good luck. Commented Oct 2, 2020 at 13:49
  • That's really a good website, thank U !! Commented Oct 2, 2020 at 16:19

1 Answer 1

0

The easiest way looks like this I guess :

for input in $var
do 
  wc -l $input
done
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks .I tried it, while it didn't work, and no error message is shown, I wonder if it is because that it concerns file not normal variables of strings
the script must be run in the same directory of files that will "counted".
All the code is in a shell script, and I put the for loop at the end of the script.
Thanks YLR, it works, I had some syntax errors, thanks a lot!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.