read string from file into variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting read string from file into variable
# 1  
Old 07-29-2009
read string from file into variable

Hello,
I need to read from a file consisting of only one integer and enter that number into variable.can anyone help?
the script is written in cshell.
thanks.
# 2  
Old 07-29-2009
Code:
 
var=`cat file`

# 3  
Old 07-29-2009
thanks a lot.works great.
# 4  
Old 07-29-2009
With bash and ksh you can also do :
Code:
var=$(<file)

Jean-Pierre.
# 5  
Old 07-29-2009
Quote:
Originally Posted by offerbukra
Hello,
I need to read from a file consisting of only one integer and enter that number into variable.can anyone help?
the script is written in cshell.
thanks.

Top Ten Reasons not to use the C shell
Csh problems
Csh Programming Considered Harmful
In any Bourne-type shell:
Code:
read var < file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to read file, and replace certain string with another string?

Hi all, the value in the following file is just an example. It could be a different value/network addresses. Here is my example of initial output in a file name net.txt Initial Output, net.txt The goal is to produce the following format which is to convert from CIDR to Netmask... (6 Replies)
Discussion started by: type8code0
6 Replies

2. Shell Programming and Scripting

Read variable name from file and use this?

I would like to read a variable name from file and I would like to use this... e.g. VARIABLE1=XXXXXX File.txt $VARIABLE1 Shell for STRING in `cat File.txt` echo $STRING done I would like the print XXXXXX. It's possible????:confused: Thanks :) (7 Replies)
Discussion started by: pinguc
7 Replies

3. Shell Programming and Scripting

replace (sed?) a string in file with multiple lines (string) from variable

Can someone tell me how I can do this? e.g: a=$(echo -e wert trewt ertert ertert ertert erttert erterte rterter tertertert ert) How do i replace the STRING with $a? I try this: sed -i 's/STRING/'"$a"'/g' filename.ext but this don' t work (2 Replies)
Discussion started by: jforce
2 Replies

4. Shell Programming and Scripting

Read Line and sent as variable for each string

Hi , I want to read below output, lets called it output1.txt and each string for every line will be declare as a variables. This is the input file 196 server_a server_unix_2 FW 196 server_b server_win_1 CD 196 server_c server_win_2 CD 196 server_bd ... (2 Replies)
Discussion started by: sQew
2 Replies

5. Shell Programming and Scripting

How read the part of the string into a variable?

Hi, I'm using bash and brand new to shell script. I would like to do the following. I have a string which is "UPDATE=1.0". I would like to read the value "1.0" alone in a variable. i.e the things afer "=" How do I do that? Thanks, (1 Reply)
Discussion started by: scriptfriend
1 Replies

6. Shell Programming and Scripting

want to read variable for the file

Hi, i have one file which has list of data like this xemp 42 yeet 87 wax 223 dyne 442 i want to read each of in for loop from the script can you give me syntax Use code tags, ty. (2 Replies)
Discussion started by: mail2sant
2 Replies

7. Shell Programming and Scripting

Appending string, variable to file at the start and string at end

Hi , I have below file with 13 columns. I need 2-13 columns seperated by comma and I want to append each row with a string "INSERT INTO xxx" in the begining as 1st column and then a variable "$node" and then $2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13 and at the end another string " ; COMMIT;" ... (4 Replies)
Discussion started by: Vaddadi
4 Replies

8. Shell Programming and Scripting

Using sed to replace a string in file with a string in a variable that contains spaces

Hi, i call my shell like: my_shell "my project name" my script: #!/bin/bash -vx projectname=$1 sed s/'PROJECT_NAME ='/'PROJECT_NAME = '$projectname/ <test_config_doxy >temp cp temp test_config_doxy the following error occurres: sed s/'PROJECT_NAME ... (2 Replies)
Discussion started by: vivelafete
2 Replies

9. Shell Programming and Scripting

Search for string in a file and extract another string to a variable

Hi, guys. I have one question: I need to search for a string in a file, and then extract another string from the file and assign it to a variable. For example: the contents of the file (group) is below: ... ftp:x:23: mail:x:34 ... testing:x:2001 sales:x:2002 development:x:2003 ...... (6 Replies)
Discussion started by: daikeyang
6 Replies

10. 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
Login or Register to Ask a Question