Assigning variable using script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Assigning variable using script
# 8  
Old 09-30-2012
Quote:
Originally Posted by emily
Hi,
It did work fine.
I have used sed for the simple task like renaming some common text in the file.
But whenever it comes to non-regular expression use, I am complete naive for it.

Code:
sed -e "s/oldname/newname/" file > file1

Also what does this command does
Code:
 grep -E '^[0-9]+'

?
It seems to aligned them, but how it is suppose to be used?

thanks again,
Code:
 grep -E '^[0-9]+'

?

finds the line starting(^) with any digit ([0-9])

Did my previous command serve your purpose? Outputs like 222,22-33,44,..... in one line.
# 9  
Old 09-30-2012
Hi,
This command
Code:
 grep -A 2 "Jobs Aborted" file | sed 's/.*: //' | grep -E '^[0-9]+'

serve my purpose.

Thanks,

---------- Post updated at 10:57 AM ---------- Previous update was at 10:44 AM ----------

Hi, in the bash script below
Code:
DATA=/11/store/data/

if [ "$2" = "A1" ]; then
FINALPATH=$DATA/Run2012A/DoubleElectron/AOD/PromptReco-v1
elif [ "$2" = "A2" ]; then
FINALPATH=$DATA/Run2012A/DoubleElectron/AOD/PromptReco-v2
elif [ "$2" = "A4" ]; then
FINALPATH=$DATA/Run2012A/DoubleElectron/AOD/PromptReco-v4
elif [ "$2" = "A5" ]; then
fi

GetFileName() {
    echo '>>>>Check, DataPATH is: '$FINALPATH
    pause

    find $FINALPATH -name "*root" > $OUTPUTFILE
    echo  $2"_dataFile.list"
    cp $OUTPUTFILE $ANALYZERPATH/File
    echo '>>> Copied OutPut : '$ANALYZERPATH/File/$OUTPUTFILE
    echo '===========================DONE======================== '
    echo '                                            '
}

elif  [ "$1" = "find" ]; then
        GetFileName
fi

I would call it like
Code:
 ./script find A1 A1_datafile.list

I want $OUTPUTFILE to be defined in the function as like,
$2"_datafile.list" . But it failed to work.

Any hint?

thanks
# 10  
Old 09-30-2012
I am a bit confused with the code. elif instead of if in the ending section?

Code:
DATA=/11/store/data/

if [ "$2" = "A1" ]; then
  FINALPATH=$DATA/Run2012A/DoubleElectron/AOD/PromptReco-v1
elif [ "$2" = "A2" ]; then
  FINALPATH=$DATA/Run2012A/DoubleElectron/AOD/PromptReco-v2
elif [ "$2" = "A4" ]; then
  FINALPATH=$DATA/Run2012A/DoubleElectron/AOD/PromptReco-v4
elif [ "$2" = "A5" ]; then
fi

GetFileName() {
    echo '>>>>Check, DataPATH is: '$FINALPATH
    pause

    OUTPUTFILE=$(echo $2"_datafile.list")   # is this what you need?
    
    find $FINALPATH -name "*root" > $OUTPUTFILE
    echo  $2"_dataFile.list"
    cp $OUTPUTFILE $ANALYZERPATH/File
    echo '>>> Copied OutPut : '$ANALYZERPATH/File/$OUTPUTFILE
    echo '===========================DONE======================== '
    echo '                                            '
}

if  [ "$1" = "find" ]; then  # correction
        GetFileName
fi

# 11  
Old 09-30-2012
opps sorry./.its copy paste error..:P :P

but the original code is all fine..Smilie

---------- Post updated at 01:15 PM ---------- Previous update was at 11:35 AM ----------

No Reply..??? should not be difficult..Smilie

---------- Post updated at 01:53 PM ---------- Previous update was at 01:15 PM ----------

Quote:
Originally Posted by the_gripmaster
-A 2 tell grep to get the +2 line from the string "Jobs Aborted" because that is the line containing the numbers.

Code:
grep -A 2 "Jobs Aborted" file | sed 's/.*: //;s/,/\n/g' | while read job; do    
  echo $job
done

Hi again Smilie
I would like to modify it little.
For example, I am suppose to peform same task for some of the GREP:
1.) jobs Aborted
2.) Jobs terminated
3.) 271 Jobs with Wrapper Exit Code : 0

I wonder if some array can be formed with these strings and I could use that? Smilie

---------- Post updated at 02:26 PM ---------- Previous update was at 01:53 PM ----------

Hi,
For the given string
Code:
crab:  ExitCodes Summary
 >>>>>>>>> 271 Jobs with Wrapper Exit Code : 0
         List of jobs: 3,12,14,20-21,24-25,27,29-30,33,36,38,41,52-53,59-60,62,64,71,73,75,77,82-84,89-91,98-99,102,104,107-110,112,116,120-123,126-1\
29,132-134,136,139,141-143,145-146,148,151-155,159-160,164,168,181-182,191,197,201-202,205,209-217,219-220,222,224,226-227,229-230,232-234,252,257,25\
9-260,266,269,271-275,283,285-286,289,292-293,295,297-298,304-307,315,326-327,330-331,335,340,343-344,346-348,350-351,356,359,361,367-370,374-375,377\
,383-384,392,400,410,421,424,429-430,436,443,447,450,452,454,465,467,469,471,473,492,499-500,508,512,516,521,528,548-549,553,556,559,567,569,571,582,\
586-588,590,594,596-597,600,607-608,612,614,616,619,624,628,630,632,637-640,644,646-647,658,662,666,673-675,680,687,692,699-700,702,708,720,725,731,7\
35,737,740,743,748,750,752,754,764,769-772,778,781,786,790,796,799,805,807,810,813,821,823,825,827,829,837-841,846-848,850,852-854,856-858,870-871,87\
4-876,880,1114

I GREP the following "Wrapper Exit Code : 0". But while processing some other commands on the no's, it added the extra '0' as well..????


Thanks,
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Assigning any number to the variable in cshell script

Hello Guys, I would like to ask you for a favor. Could you please help me how can I assign any number as the parameter to a, from stdin (-c), in the following command line by using the 'switch' in a script? awk '$8>a {print "File name:" $5,$8}' I would also appreciate if you can share any... (1 Reply)
Discussion started by: Padavan
1 Replies

2. Shell Programming and Scripting

Assigning value to a variable

Unable to get the value to a variable. set -x cd $HOME echo "Enter the server name" read a echo $a i=4 j=1 k = ps -ef | awk '/server1/{ print $4 }' | tail -$i | head -$j` echo $k When I do the same in command line it works, however the same does not work when I provide that in the... (1 Reply)
Discussion started by: venkidhadha
1 Replies

3. Solaris

Assigning an expression to a variable in shell script

i am trying to assign the following expression to a variable in Unix shell script and want to use that variable in some other expression. But unable to get the required thing done. Please help with this.... This is the expression which i want to provide as input the variable date '+%y:%m:%d' |... (3 Replies)
Discussion started by: ssk250
3 Replies

4. Shell Programming and Scripting

problem in assigning value to variable have value fo other variable

my script is some thing like this i11="{1,2,3,4,5,6,7,8,9,10,11,}" echo "enter value" read value ..............suppose i11 x="$value" echo "$($value)" .............the echo should be {1,2,3,4,5,6,7,8,9,10,11,} but its showing "i11" only. plz help me out to get desired... (10 Replies)
Discussion started by: sagar_1986
10 Replies

5. Shell Programming and Scripting

Script stops running after assigning empty string for a variable

Hi, This is the first time I see something like this, and I don't why it happens. Please give me some help. I am really appreciate it. Basically I am trying to remove all empty lines of an input.. #!/bin/bash set -e set -x str1=`echo -e "\nhaha" | grep -v ^$` #str2=`echo -e "\n" |... (4 Replies)
Discussion started by: yoyomano
4 Replies

6. Shell Programming and Scripting

Assigning value to script variable

I am trying to assign the value returned by wc command to a script variale. Code: FILES_NAME='files_list'; NO_OF_FILES =${wc -l $FILES_NAME}`; When the above code is run : it throws the error ${wc -l $FILES_NAME}: The specified substitution is not valid for this command. what is the... (6 Replies)
Discussion started by: hiten.r.chauhan
6 Replies

7. Shell Programming and Scripting

Assigning return value of an embedded SQL in a shell script variable

I've a script of the following form calling a simple sql that counts the no of rows as based on some conditions. I want the count returned by the sql to get assigned to the variable sql_ret_val1. However I'm finding that this var is always getting assigned a value of 0. I have verified by executing... (1 Reply)
Discussion started by: MxC
1 Replies

8. Shell Programming and Scripting

ksh help assigning specific values to variable in script

Hi - Help needed. I have an input file that looks something like this, but with a lot more entries: A Customer1 B 4500 C 8000 A Customer2 B 6422 C 8922 I need to be able to print details for each customer on one line per customer. ie. if I could print these to a file and then cat... (3 Replies)
Discussion started by: frustrated1
3 Replies

9. Shell Programming and Scripting

Removing a character from a variable and assigning it to another variable?

Hi folks. I have this variable called FirstIN that contains something like this: 001,002,003,004... I am trying to assign the content of this variable into ModifiedIN but with the following format : 001 002 003 004...(changing the commas for spaces) I thought about using sed but i am not... (17 Replies)
Discussion started by: Stephan
17 Replies

10. Shell Programming and Scripting

Assigning a value to variable

Another newbie to Unix scripting Q.. How do you assign a value resulting from a command, such as awk, to a variable. I am currently trying:- $awk '{print $1}' file1 > variable1 with no change to $variable1. The line: $awk '{print $1}' file1 does print the first line of the... (3 Replies)
Discussion started by: sirtrancealot
3 Replies
Login or Register to Ask a Question