Problem while assign string (words with tab) to a variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem while assign string (words with tab) to a variable
# 1  
Old 01-02-2013
Problem while assign string (words with tab) to a variable

Hi,

I have a String(words with tab space) in a file ->file1.txt
Code:
 0xxxx    11      test  $aa$   8.43

when i read the file and assign to variable
Code:
  value=$(cat file1.txt)
              echo $value

i get the output without tab spaces.
Code:
  0xxxx 11 test $aa$ 8.43

How to assign string to variable with tab spaces.

Please Suggest me,


Thank You & Regards
Nanthagopal A
# 2  
Old 01-02-2013
Try this:
Code:
value="$(cat file1.txt)"

Code:
echo "${value}"

This User Gave Thanks to Klashxx For This Post:
# 3  
Old 01-02-2013
Actually the quotes are not necessary for the assignment:
Code:
value=$(cat file1.txt)


--
or if it is always just one line:
Code:
read value < file1.txt

or

Code:
IFS= read -r value < file1.txt

to preserve leading and closing spaces and backslash characters..
These 2 Users Gave Thanks to Scrutinizer For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem with variable assign

Hi all, i'm new in shell script. i'm trying to do this: mypid="ps | grep whileloop.sh | sed -n 1p | tr -s ' ' | cut -f2 -d' '" i'm trying to assign the pid number to variable mypid, but it doesn't work...how can i do? thanks (5 Replies)
Discussion started by: Marina2013
5 Replies

2. Shell Programming and Scripting

Assign a variable the nth character of a string.

I see a millioin ways to do this with echo, but what I wan to do is assign a variable the "nth" character of an incoming parameter to a ksh script. $1 will be "pia" I need to assign the first character to stmttype. (10 Replies)
Discussion started by: klarue
10 Replies

3. UNIX for Dummies Questions & Answers

Vi - insert a tab between words?

I have several lines in a file that I want to replace a space with a tab. For example: 111047 Julie Jones email@email.com 111047 Julie Jones email@email.com I want to replace the space after the word "jones" with a tab. How do I achieve that in Vi? Please assist. Thanks! (5 Replies)
Discussion started by: onlinelearner02
5 Replies

4. Shell Programming and Scripting

need to assign a string to a variable

Hello Experts, In my script i am using the below syntax /usr/bin/head -1 /opt/chumma.txt | /usr/bin/cut -d " " -f3 output of this one is --> Monday I want to store this String in a variable (i.e) j or k... Give me some idea experts. Thanks in advance. (7 Replies)
Discussion started by: natraj005
7 Replies

5. Shell Programming and Scripting

Bash assign string to variable

Hi ,I am trying to assign string to variable ,but it doesn't work Also could you show me different ways to use grep,(I am trying to get the first,second and first column form file,and I am counting the chars) let name=`grep "$id" product | cut -c6-20` (25 Replies)
Discussion started by: lio123
25 Replies

6. Shell Programming and Scripting

Assign words in a string to array

I have a string as "yes why not" I want to create one array variable with contents as one word per place in array.. for above string,the array variable should contain... x="yes,why,not" x = yes x = why x = not Please help me,I am stuck up in the problem since 2 days... (3 Replies)
Discussion started by: uday26
3 Replies

7. Shell Programming and Scripting

How to assign the Pattern Search string as Input Variable

guys, I need to know how to assing pattern matched string as an input command variable. Here it goes' My script is something like this. ./routing.sh <Server> <enable|disable> ## This Script takes an input <Server> variable from this line of the script ## echo $1 | egrep... (1 Reply)
Discussion started by: raghunsi
1 Replies

8. Shell Programming and Scripting

read and assign each character from the string to a variable

How... can I read input by a user character by cahracter. And assign each character from the string to a variable? Any help would be greatly appreciated! Thank you! (1 Reply)
Discussion started by: Tek-E
1 Replies

9. Shell Programming and Scripting

Problem when assign the array with the string index

I come across the problems when assigning the array in the script below . How to use the array with the 'string index' correctly ? When I assign a new string index , the array elements that are previously assigned are all changed .:eek::eek::eek: $ array=211 $ echo ${array} 211 $... (4 Replies)
Discussion started by: youareapkman
4 Replies

10. Shell Programming and Scripting

How to assign variable from a string having blanks in between

Hi All, I am new to bash scripting. I need your help to removing spaces from a string and assign them to different variables. Iwant to call script with one command line argument which is file name which containes different attributes their type and different values eg ... (1 Reply)
Discussion started by: flextronics
1 Replies
Login or Register to Ask a Question