Read multiple values into one variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read multiple values into one variable
# 1  
Old 03-16-2015
Question Read multiple values into one variable

Hello everybody,

I am trying to assign multiple values from text into a single variable in bash.

Source TXT:

Code:
1 THIS IS THE ENTITY1 NAME1
2 THIS IS THE ENTITY2 NAME2
3 THIS IS THE ENTITY3 NAME3

Code:
  while read id entity name
     do
        printf "$id" "$entity" "$name"
done < "$sourceTXT"

In this example I want to assign "THIS IS THE ENTITY1" to $entity rather than "THIS"

Hope it is clear ..

Last edited by rbatte1; 03-17-2015 at 12:32 PM.. Reason: Added CODE tags
# 2  
Old 03-16-2015
Please use code tags as required by forum rules!

You can't. Unless you use different delimiters within the line. Workaround:
Code:
while read id A B C D name REST
     do entity="$A $B $C $D"
        printf "$id" "$entity" "$name"
     done < "$sourceTXT"

This User Gave Thanks to RudiC For This Post:
# 3  
Old 03-16-2015
Quote:
Originally Posted by RudiC
Please use code tags as required by forum rules!

You can't. Unless you use different delimiters within the line. Workaround:
Code:
while read id A B C D name REST
     do entity="$A $B $C $D"
        printf "$id" "$entity" "$name"
     done < "$sourceTXT"

Sorry for not following the rules.. That will help thank you
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read record from the text file contain multiple separated values & assign those values to variables

I have a file containing multiple values, some of them are pipe separated which are to be read as separate values and some of them are single value all are these need to store in variables. I need to read this file which is an input to my script Config.txt file name, first path, second... (7 Replies)
Discussion started by: ketanraut
7 Replies

2. Shell Programming and Scripting

Read in shell variable values from a file

Hello, I have a simple script that runs an application, # these arguments have the same value for all splits ARCH=12.11.1 BATCHES=50 EPOCHS=5000 LEARN_MODE=ONLINE LEARN_RATE=0.25 PROJ=02_BT_12.11.1.proj echo "processing split A on hex" cd A/ DATA_SET=S2A_v1_12.1.1_1... (4 Replies)
Discussion started by: LMHmedchem
4 Replies

3. Shell Programming and Scripting

Variable with multiple values

Hello I need to alter a script to check for a flag file but there are now more than one type of flag file in my directory. Basically if any of these flg files exist then the MASK value should be set? Flag files to be included in assignment to variable e2e_scheduled*.flg COLL_STOP*.flg... (1 Reply)
Discussion started by: andymay
1 Replies

4. Shell Programming and Scripting

[SOLVED] UNIX FOR loop to read a variable with multiple values

Hi, I have a variable which stores file names as a result of find command. I need to delete all these files one by one, i.e. by a loop. Can anyone tell me how can it be done? The variable f2d has the file names like these abc.txt bcd.txt fff.txt gef.txt Now I have used a loop as... (12 Replies)
Discussion started by: jhilmil
12 Replies

5. UNIX for Dummies Questions & Answers

How to store/read multiple values from a varible

Hi, when I enter 'ps -ef| grep process_name'/'psu | grep process_name', i am getting multiple number of lines output( i mean multiple no of processes).how can i store it one by one and echo it in the same way(one by one). part of script is var1=$(remsh hostname -l username ps -ef|grep... (2 Replies)
Discussion started by: jeanzibbin
2 Replies

6. Shell Programming and Scripting

Read multiple values from sqlplus in perl

Hello Need your kind support to solve the below issue I am returning oracle column value via sqlplus in the below code my $sqlplus_settings = ''; my $newval = qx { sqlplus -s $connect_string <<EOF set pages 0 feed off $sqlplus_settings select (rcrd_cnt) from... (4 Replies)
Discussion started by: Pratik4891
4 Replies

7. Fedora

How to read a text file and assign the values in the same to a variable in loop

Hi, I have a text file with multiple lines, each having data in the below format <DOB>,<ADDRESS> I have to write a script which reads each line in the text file in loop, assign the values to these variables and do some further processing in it. Using the following code prints the... (1 Reply)
Discussion started by: manishab00
1 Replies

8. Shell Programming and Scripting

Read the csv file and assign the values in to variable

I have a csv file with the values seperated by commas.I want to extract these values one by one and assign to a variable using shell script.Any ideas or code? (11 Replies)
Discussion started by: rajbal
11 Replies

9. Shell Programming and Scripting

Read a file and assign the values to a variable

i have a file in this format curyymm PRVYYMM CDDMmmYY bddMmmyy eddMmmyy --------- ------- ------------ ---------- ----------- 0906 0905 09Jun09 01Jun09 30Jun09 ----------- --------- ------------ ------------ ----------- i need to read the... (5 Replies)
Discussion started by: depakjan
5 Replies

10. UNIX for Dummies Questions & Answers

How can I read variable values from file?

Hi, I want to pratmeterze my scripts like, my confRsync file contains varibale values for 1. host 2. Destination and 3. source like this, I want to read this values from this and assing to my makeRsyn.sh file's varibales. how to do this? (1 Reply)
Discussion started by: redlotus72
1 Replies
Login or Register to Ask a Question