Changing the variable using awk?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Changing the variable using awk?
# 1  
Old 03-27-2013
Changing the variable using awk?

Dear all,
I have kind of used both the awk/sed command and found them really useful.
But at the necessity I am having right now, I need help.
Actually, I would like to do the following in file script.sh
Code:
  
PATH535[1]="/eos/uscms/store/user/pooja04//analysis2012/535/mc/summer12/002/tt/"

there is whole script which works all fine, now my present task is to somehow read the RED LINE , and
change the "tt" to various varaible.
So I have something in mind as:

Code:
GREP[1]="ttbar"
GREP[2]="DYJets50"
GREP[3]="zgamma"
GREP[4]="mJetA"
GREP[5]="mJetB"

for FileNameIndx in "${GREP[@]}"
      do
        change the tt  in script.sh to GREP[1]
        do something ......
      done

Can somebody help me with the BLUE color command, how shall I implement that?

thanks in advance
emily
# 2  
Old 03-27-2013
Something like:
Code:
sed -i "/^PATH535/s#/tt/#/${GREP[1]}/#g" script.sh

(if your sed doesn't support -i you could use a temporary file)

EDIT: If you want an awk solution then you could have something like:
Code:
awk -F/ -vnewdir=${GREP[1]} '/^PATH535/ {$NF=newdir}1' OFS=/ script.sh

(assuming you know tt is always the last element in the path)

Last edited by CarloM; 03-27-2013 at 02:56 PM..
# 3  
Old 03-27-2013
Quote:
Originally Posted by CarloM
Something like:
Code:
sed -i "s#/tt/#/${GREP[1]}/#g' script.sh

(if your sed doesn't support -i you could use a temporary file)
SmilieSmilie

Thank
emily
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Dynamically changing environment variable

Linux Redhat, BASH Shell. I want to put this in my .bash_profile I have log files that go to directory paths based in part on other variables such as went DB Name is set in memory. So if the DB Name changes the path to the log file changes. How do I create an environment variable I put into... (6 Replies)
Discussion started by: guessingo
6 Replies

2. UNIX for Dummies Questions & Answers

Changing Path Variable

Blank Blank Blank (11 Replies)
Discussion started by: pvibien
11 Replies

3. UNIX for Dummies Questions & Answers

Getting input and changing variable?

Hi I am new to scripting and have a function in my .sh script file that outputs a html radio button form weather_forecast_config() { echo "" echo "<html><head><title>Welcome</title></head>" echo "<body>" echo "<h2>Weather Forecast - Change City</h2>" echo "<form name="input"... (5 Replies)
Discussion started by: scriptnewbie
5 Replies

4. Shell Programming and Scripting

Changing a global variable to agrv

Hi Guys, I am dealing with some perl scripts written by someone else. There are alot of global variables set at the top of the scripts, which needs to be edited for different users who run the scripts. I am tring to change them so these variables can be set as arguments when running it from the... (1 Reply)
Discussion started by: da2013
1 Replies

5. Shell Programming and Scripting

Changing variable name in for loop

Hi All please help if possible. I am a Unix novice. I have a similar question to the one posted by yonderboy at about a year ago. However his solution does not work for me. The pseudo code for my problem is as follows: for fund in 1 2 3 4 if (FTP is successfully) then FILE_SENT_fund... (2 Replies)
Discussion started by: Seether
2 Replies

6. Shell Programming and Scripting

Changing a shell template variable

I'm trying to use a custom command in the configServer loadalert.txt file. the problem is that any command that I place inside the square brackets is simply not working. This is a multi-part message in MIME format. -------------- Content-Type: text/plain; Content-Transfer-Encoding: 7bit ... (2 Replies)
Discussion started by: kshazad
2 Replies

7. Shell Programming and Scripting

Changing a variable Question

I have a variable: $FILENAME = /XXXX/XXXX/XXXX/file.dat I want to set another variable that will give me this: $FILENAME2=filea.dat So basically i'm chopping up variable $FILENAME. Not sure cut will do this as i'm looking at different directories so the characther length may be... (2 Replies)
Discussion started by: Pablo_beezo
2 Replies

8. Shell Programming and Scripting

Help with awk script, changing the FS for a single variable

Hi all, im new to awk and would apreciate if you could tell me how to do this, i have a file with several entries like this: 2008-09-09 21:57:45 44 403 CUSTOM_EVENT Upgrade - end1 2008-09-09 21:57:46 45 403 CUSTOM_EVENT Component Check - start... (3 Replies)
Discussion started by: sx3v1l_1n51de
3 Replies

9. AIX

rerun .profile after changing variable

I changed a $variable in my .profile (AIX unix). I know I could exit out and logon onto unix again, but how do I rerun the .profile at the command line? (2 Replies)
Discussion started by: sboxtops
2 Replies

10. Shell Programming and Scripting

IFS changing the variable value

Hi, I have a while read loop that reads files in a directory and process. The files have spaces in between, so I have the IFS=\n to to read the whole line as one file name. The read works fine but I have a problem with another variable that I set in the beginning of the script. The variable... (1 Reply)
Discussion started by: pvar
1 Replies
Login or Register to Ask a Question