Creating variables dynamically and using it in script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Creating variables dynamically and using it in script?
# 8  
Old 10-18-2011
Sorry my bad, I should have been more specific. This is what i see when run the command

Code:
egrep a|b|c temp.log
-bash: a: command not found
-bash: b: command not found

The command prompt does not return after that, untill i hit CTRL+C. Is it that egrep is not allowed by my system?
# 9  
Old 10-18-2011
That doesn't work because "a|b|c" is not in quotes. It has to be, or the shell assumes you're running
Code:
egrep a | b | c

It freezes because 'egrep a' is not given a filename and tries to read from standard input.

Kudos for trying to test the solution instead of just copypasting though! Smilie

You definitely have egrep.
This User Gave Thanks to Corona688 For This Post:
# 10  
Old 10-18-2011
Perhaps the debug output line should have been:

Code:
echo egrep \""${ARR[*]}"\" $FILE

Giving:
Code:
$ ./script.sh

egrep "a|b|c|d" file1
egrep "e|f" file2
egrep "g|h|i|j|k|l" file3

$

This User Gave Thanks to Chubler_XL For This Post:
# 11  
Old 10-19-2011
Java

Thanks guys...it really helped. Appreciate your help

---------- Post updated 10-19-11 at 04:56 PM ---------- Previous update was 10-18-11 at 05:16 PM ----------

One more question to related to the egrep. Your earlier suggestions work fine, but I have a little more complex issue. Like earlier suggested in am using

Code:
egrep "a|b|c|d" file1

and it works fine, but it also get the other matching patterns of a. For example my file also has some text like:
Code:
xxxayyy , xyza and a

Currently it gets every thing like: "xxxayyy", "xyza" and "a" and I just want to get "a" from the file and not other text can you please suggest how can i use the above " egrep" to filter these and not .

Thanks in advance ...

Last edited by davidtd; 10-19-2011 at 05:59 PM.. Reason: Added more text
# 12  
Old 10-19-2011
Try using the \b word boundries like this:
Code:
egrep "\ba\b|\bword\b" files

This User Gave Thanks to Chubler_XL For This Post:
# 13  
Old 10-21-2011
Thanks guys.... you guys are amazing. Please continue the good work.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Creating IN list in PLSQL script dynamically by using shell script

Hi all, I have a PLSQL script which has a IN list where it takes some ids as input. For example SELECT * FROM EMPLOYEE WHERE EMPLOYEE_ID IN (comma separated list ) I want to run this quest inside a shell script but I would like to prepare the IN list dynamically where the employee ids... (1 Reply)
Discussion started by: LoneRanger
1 Replies

2. Shell Programming and Scripting

Dynamically creating file names from portions of another file name

Not sure how to do the following, but any help would be appreciated. Has to be done using C shell (sorry about that). I have about 300 files that I need this done for, but I am only going to give one example. I will just need to know how to execute your solution through some type of loop to get... (2 Replies)
Discussion started by: jclanc8
2 Replies

3. Homework & Coursework Questions

Creating a .profile, displaying system variables, and creating an alias

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Here is what I am supposed to do, word for word from my assignment page: 1. Create/modify and print a... (2 Replies)
Discussion started by: Jagst3r21
2 Replies

4. Shell Programming and Scripting

Creating variables in bash

I am writing some scripts using bash and am wondering if there is a better way to perform the following set of formatting variables. s1=" " s2=" " s3=" " s4=" " s5=" " s6=" " s7=" " s8=" " frmt_titl="${bYl}%s${nClor}\n" frmt1_titl="${s1}$frmt_titl"... (10 Replies)
Discussion started by: kristinu
10 Replies

5. Programming

Dynamically creating structure in C/C++ program

Hi, For one of the project which i am working on i need to write a cpp code such that it will create the structure dynamically instead of reading it from header file. For example we have a program which is reading a binary file according to the structure mentioned in header file. But we... (0 Replies)
Discussion started by: AmbikaValagonda
0 Replies

6. Shell Programming and Scripting

need help with creating directories and variables

i'm trying to write a script that has 2 variables, and uses the 1st variable as a number and the 2nd a name to create directories. so if you typed in ./myscript 5 week, it would create 5 directories named week1 - week5. whenever i run this, i get an error message saying week5 already exists, so i... (3 Replies)
Discussion started by: layne2kim
3 Replies

7. Solaris

Creating script adding 3 different variables in 3 columns

I have 3 variables with different information.. they look like this (row-wise aswell): Variable1 = Roland Kalle Dalius Variable2 = ake123 ler321 kaf434 Variable3 = Richardsen Sworden Lokthar How can I sort them by variable3 alphabetical and add them into the same output so... (0 Replies)
Discussion started by: Prantare
0 Replies

8. Shell Programming and Scripting

Dynamically creating text files using shell script

Hi All, I want to create a shell script which dynamically create text files. i am using the following script $i=1 while do cat > test_$i.txt done but while running the script it was stopping(the cursor not going to next step, i have to enter ctrl+c to make it stop). it is creating only... (2 Replies)
Discussion started by: KiranKumarKarre
2 Replies

9. Shell Programming and Scripting

Dynamically Creating and Printing to Files

Hello, If anyone could help me out with this, it would be greatly appreciated. I am trying to dynamically create files and print to them. Here is the code I have to so far. thanks. if (n < 5000 ) { # do nothing } else { n = 0; filenum++; # out = ("out" filenum); } ... (1 Reply)
Discussion started by: Laud12345
1 Replies

10. Shell Programming and Scripting

dynamically creating a variable name

Hi ! I have the following situation - ##First variable variableA=JOB_A ##bunch of other variable JOB_A_RESTART=cleanupJobA JOB_B_RESTART=cleanupJobB JOB_C_RESTART=cleanupJobC now i need a script which would - 1. take the first variable 2. create a new variable name... (2 Replies)
Discussion started by: hsahay
2 Replies
Login or Register to Ask a Question