How to make a number in a text file a variable?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to make a number in a text file a variable?
# 1  
Old 08-23-2006
How to make a number in a text file a variable?

OK this one sounds like it should be a natural...

it must be possible to send a number say 200 to a text file and later use it as a variable?

yada yada > file.txt

how would I retrieve that number to use as a variable? Is this possible?
# 2  
Old 08-23-2006
looking for something like this ...

just a pointer

Code:
> echo "200" > ert
> var=`cat ert`
> echo $var
200

# 3  
Old 08-23-2006
ah thanks... I'd tried that but not with quotation marks!!! Smilie
# 4  
Old 08-23-2006
quotes is not at all needed

Code:
echo 200 > ert
var=`cat ert`
echo $var
200

# 5  
Old 08-23-2006
I've sat here for an hour trying to get that variable to show up in an awk...

Code:
cat gzipsize.txt | awk '{print "echo",$1,$2} > master.txt

I've got a variable in my script called $size and i want to print it after the second field from the text file.

Could you please give me a clue on how to effectively insert variables from my script into the awk?

My book seems to have no examples of this and the many ways I've got from googling has led down blind paths that didn't work.
# 6  
Old 08-23-2006
just to display the command line

Code:
wc -l < zom.c | awk '{ print "echo " $1 " > 1.txt" }'

and execute it in the run

Code:
wc -l < zom.c | awk '{ print "echo " $1 " > 1.txt" }' | ksh

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to make partitions in a text file?

Suppose I have a file named intro.txt and its content is as follows My name is Ankit. I am 18. I am a college student. So I want make partitions in this and store it as 1. name.txt - I am 18. 2. age.txt - I am 18. 3. student.txt -I am a college student. How do I do that in terminal? edit... (1 Reply)
Discussion started by: ANKIT ROY
1 Replies

2. Shell Programming and Scripting

Read csv file, convert the data and make one text file in UNIX shell scripting

I have input data looks like this which is a part of a csv file 7,1265,76548,"0102:04" 8,1266,76545,"0112:04" I need to make the output data should look like this and the output data will be part of text file: 7|1265000 |7654899 |A| 8|12660000 |76545999 |B| The logic behind the... (6 Replies)
Discussion started by: RJG
6 Replies

3. Shell Programming and Scripting

Make copy of text file with columns removed (based on header)

Hello, I have some tab delimited text files with a three header rows. The headers look like, (sorry the tabs look so messy). index group Name input input input input input input input input input input input... (9 Replies)
Discussion started by: LMHmedchem
9 Replies

4. Shell Programming and Scripting

Reading columns from a text file and to make an array for each column

Hi, I am not so familiar with bash scripting and would appreciate your help here. I have a text file 'input.txt' like this: 2 3 4 5 6 7 8 9 10 I want to store each column in an array like this a ={2 5 8}, b={3 6 9}, c={4 7 10} so that i can access any element, e.g b=6 for the later use. (1 Reply)
Discussion started by: Asif Siddique
1 Replies

5. Shell Programming and Scripting

Make a table from a text file

Hi, I have a pipe separated text file. Can some someone tell me how to convert it to a table? Text File contents. |Activities|Status1|Status2|Status3| ||NA|$io_running2|$io_running3| |Replication Status|NA|$running2|$running3| ||NA|$master2|$master3|... (1 Reply)
Discussion started by: rocky88
1 Replies

6. Shell Programming and Scripting

Insert a variable to a text file after fixed number of lines

Hi, I am new to unix. I need to insert a variable which contains some lines of text into a text file after fixed number of lines.. Please help me on this.. Thanks in Advance, Amrutha (3 Replies)
Discussion started by: amr89
3 Replies

7. UNIX for Dummies Questions & Answers

search all file for particular text and make changes to line 3

Hi All, I am sitting on HPUX. I want to change the exit into #exit, which appears into 3red line of code in shell scripting, wondering how shell script to be called up to perform action. I have following code in all files. Now, I need to find the text exit and replace into #exit. #!/sbin/sh... (10 Replies)
Discussion started by: alok.behria
10 Replies

8. Shell Programming and Scripting

number of fields in a text file as a variable - perl

I am looking for perl code to get following o/p. If a line has more than 7 fields then value in field 7 onwards is BHA_GRP1, BHA_GRP2, BHA_GRP3, BHA_GRP4 etc. Here is example of what I am trying to achieve. INPUT File: VAH NIC_TYPE CONFIG SIZE_GB PILO KOM BHA_GRP1 BHA_GRP2 BHA_GRP3...... 2... (1 Reply)
Discussion started by: dynamax
1 Replies

9. Shell Programming and Scripting

Number lines of file and assign variable to each number

I have a file with a list of config files numbered on the lefthand side 1-300. I need to have bash read each lines number and assign it to a variable so it can be chosen by the user called by the script later. Ex. 1 some data 2 something else 3 more stuff which number do you... (1 Reply)
Discussion started by: glev2005
1 Replies

10. Shell Programming and Scripting

[Shell] How make colums in text file ??

hi, i have little pb, i would like make a colums, but my server not recongize "\t" or i write wrong.... and iam little noobs and no know awk... #!/bin/ksh #---------------------------------------------------------------------------- # Fichiers : ctrl.sh et ctrl2005.txt ... (6 Replies)
Discussion started by: parola
6 Replies
Login or Register to Ask a Question