Help needed in reading line value into variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help needed in reading line value into variable
# 1  
Old 05-16-2012
Help needed in reading line value into variable

I have a file which has data in 8 lines:

Code:
10
34
 6
 1
 4
46
67
31

I am trying to read each value into each different variable so that I use these variables in preparing my report.

Another option is to dynamically print each line values in the report like below:

Code:
users with privA: line 1 value
users with privB: line 2 value
users with privC: line 3 value
users with privD: line 4 value
users with privE: line 5 value
users with privF: line 6 value
users with privG: line 7 value
users with privH: line 8 value

Please help me out with the correct command

Thanks in advance.

Last edited by Scrutinizer; 05-16-2012 at 06:06 PM.. Reason: code tags
# 2  
Old 05-16-2012
Try:
Code:
for priv in privA privB privC privD privE privF privG privH
do 
  read val
  echo "users with $priv: $val"
done < infile

# 3  
Old 05-17-2012
This works fine thanks you very much
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Script reading needed

Hi, I'm just learning so I would appreciate some understanding line by line on the while loop/case script below. Thanks so much. joe. echo "Good Morning." echo "Enter 1 to Add" echo "or q to quit." while do read Enter case $Enter in 1) echo "Addtion:" echo... (3 Replies)
Discussion started by: jefferj54
3 Replies

2. Shell Programming and Scripting

Reading text file, comparing a value in a line, and placing only part of the line in a variable?

I need some help. I would like to read in a text file. Take a variable such as ROW-D-01, compare it to what's in one line in the text file such as PROD/VM/ROW-D-01 and only input PROD/VM into a variable without the /ROW-D-01. Is this possible? any help is appreciated. (2 Replies)
Discussion started by: xChristopher
2 Replies

3. Shell Programming and Scripting

Reading of variable in a single line command

Hi All, Below is a sample command that I can run without any problem in the command line. Command Line dtToday=`date +%Y%m%d`; ls -ltr ./filename_${dtToday}.txt -rw-r--r-- 1 monuser oinstall 0 Jan 18 11:02 ./filename_20130118.txt But once I put that command line in file (list.txt) and... (3 Replies)
Discussion started by: padi
3 Replies

4. Shell Programming and Scripting

EXPECT: Assign variable by reading a line of text from a file

Hi All, I have been using a program on windows called AutoKey. My environment at work is Linux and I have been experimenting with expect. Very powerful. I can move my AutoKey scripts to Linux using Expect once I am educated on how to read from a file using Expect. My application would be... (1 Reply)
Discussion started by: quemalr
1 Replies

5. Shell Programming and Scripting

Help needed reading the file

I am reading a pipe delimted file having the 4 columns. The file content looks like APT|string|Application ID For App|value for env in `cat $ConfigFile` do name=`echo $env | cut -d '|' -f1` type=`echo $env | cut -d '|' -f2 prompt=`echo $env | cut -d '|' -f3` ... (5 Replies)
Discussion started by: chandu123
5 Replies

6. UNIX for Dummies Questions & Answers

Parsing file, reading each line to variable, evaluating date/time stamp of each line

So, the beginning of my script will cat & grep a file with the output directed to a new file. The data I have in this file needs to be parsed, read and evaluated. Basically, I need to identify the latest date/time stamp and then calculate whether or not it is within 15 minutes of the current... (1 Reply)
Discussion started by: hynesward
1 Replies

7. Shell Programming and Scripting

[Solved] Problem in reading a file line by line till it reaches a white line

So, I want to read line-by-line a text file with unknown number of files.... So: a=1 b=1 while ; do b=`sed -n '$ap' test` a=`expr $a + 1` $here do something with b etc done the problem is that sed does not seem to recognise the $a, even when trying sed -n ' $a p' So, I cannot read... (3 Replies)
Discussion started by: hakermania
3 Replies

8. Shell Programming and Scripting

reading the whole line from a file into a variable

Hi, I am doing : while read line do printf "%s\n" ${line} done <datafile.txt but I am not getting each single line from the data file assigned to the variable line (but only tokens/fields at a time). I also tried while IFS= read -r lineI want the whole line assigned or read into the... (2 Replies)
Discussion started by: shri_nath
2 Replies

9. Shell Programming and Scripting

reading line by line a variable

Hello, I have a variable Diskfree and I would like to read it line by line to extract information, I don't know how to get the line Diskfree=`df -h | grep dev` I want to make a loop to get each value of this line, but I don't know how to get the line. I've seen sample with standard... (4 Replies)
Discussion started by: pppswing
4 Replies

10. UNIX for Dummies Questions & Answers

reading a line into a variable in unix

hi... i need to open a file and read it line by line, and capture that it in to some variable and manipulate... i need to get a line in to a variable please help :confused: (1 Reply)
Discussion started by: lmadhuri
1 Replies
Login or Register to Ask a Question