How to evaluate expressions in file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to evaluate expressions in file
# 1  
Old 09-05-2012
How to evaluate expressions in file

I have a situation where i need to evaluate expression and do substitutions in file

Code:
file.ports
port1=`expr $STARTINGPORT + 1`
port2=`expr $STARTINGPORT + 2`
port3=`expr $STARTINGPORT + 3`

Intended output If my STARINGPORT is 100
port1=101
port2=102
port3=103

Can anyone please advise whats the best way to do it and if it possible using sed
# 2  
Old 09-05-2012
You have yourself a shell script there. The best thing for evaluating a shell script is usually a shell.

Then you can just echo all the variables back out.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copy file and evaluate its internal variables

Hi I have been trying to figure a way to copy a file, (a template), that has internal variables. Using the values as defined for those variables in another script. So a file called x - #! /bin/bash D=aa.$X.bb And file y #! /bin/bash X=6 while read line do eval echo... (5 Replies)
Discussion started by: steadyonabix
5 Replies

2. UNIX for Dummies Questions & Answers

How does ||: evaluate?

In BASH, how does ||: get interpreted. I know || is logical or. And I believe : evaluates to true. Can someone give a thorough explanation for this usage? Example for i in $IGGY do && skipdb=1 || : (6 Replies)
Discussion started by: glev2005
6 Replies

3. Shell Programming and Scripting

Extract expressions between two strings in html file

Hello guys, I'm trying to extract all the expressions between the following tags: <b></b> from a HTML file. This is how it looks: big lines containing several dozens expressions (made of 1,2,3,4,6 or even 7 words) I would like to extract: <b>bla ble</b>bla ble</td><tr valign="top"><td... (3 Replies)
Discussion started by: bobylapointe
3 Replies

4. UNIX for Dummies Questions & Answers

Read a flat file, evaluate and create output. UNIX SCRIPT.

Hi all, I have a flat file as below; 470423495|1||TSA-A000073800||1|||1 471423495|1||TSA-A000073800||5|||5 472423495|1||TSA-A000073800||2|||7 473423495|1||TSA-A000073800||3|||3 I like to create a Unix script. The script have to valuate the last two columns, if the values are... (4 Replies)
Discussion started by: mrreds
4 Replies

5. Shell Programming and Scripting

How to evaluate the value of a variable ?

How to evaluate the value of a variable ? For example: a=var $a=value !!!error happens!!! I want to evaluate var=value, how to realize it? Thanks! ---------- Post updated at 03:37 AM ---------- Previous update was at 02:22 AM ---------- I am using linux bash. a=var $a=value... (4 Replies)
Discussion started by: 915086731
4 Replies

6. Shell Programming and Scripting

Output section of file between two expressions multiple times

Attached is the exact ouput of a vmware VDR log file I am working with but what I am trying to achieve is as follows: I need to output sections of the file using the string "Normal backup" as the start and "Duration" as the end to seperate files so I can then manipulate them further to create... (2 Replies)
Discussion started by: jelloir
2 Replies

7. UNIX for Dummies Questions & Answers

Cut file using regular expressions

I have a file with approximately 262,000 fields and I want to split it according to pairs of fields. The fields have headers and I want to create smaller files with just the columns between the fields (specified fields inclusive). For example, I just want the columns "set" and "test", with the... (3 Replies)
Discussion started by: etownbetty
3 Replies

8. Shell Programming and Scripting

Evaluate the value of a variable?

I have variables: FOO="Text" BAR="FOO" I'd like to be able to evaluate the variable named as the value of $BAR. echo $FOO Text echo $BAR FOO This is what I'd like to do: echo ${$BAR} (this won't work) Text (3 Replies)
Discussion started by: Ilja
3 Replies

9. Shell Programming and Scripting

How to evaluate the value read from a file?

Hi, Could someone please help me with how to do the following? Say I have a flat file test.lst and the content of the file is: Report Date - `date '+%m%d%Y'` I'm trying the following while read myLine do echo ${myLine} done<test.lst This prints Report Date - `date... (1 Reply)
Discussion started by: arunsoman80
1 Replies

10. UNIX for Dummies Questions & Answers

grep where expressions reside in file

I have a program that displays many messages on stdout. I have another file that contain error messages only - Each line is a separate message. (msgs.txt) I am trying to show only the errors and not all the output. I tried this but got nothing: myprog | grep < msgs.txt I also tried... (2 Replies)
Discussion started by: GMMike
2 Replies
Login or Register to Ask a Question