concatenate variables problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting concatenate variables problem
# 1  
Old 12-22-2010
concatenate variables problem

Hello,

I have a tricky problem:

I have a $file with a variable number of occurrences of "ORA-" (in this case two)
Code:
..........
EXP-00008: ORACLE error 3113 encountered
ORA-03113: end-of-file on communication channel
EXP-00056: ORACLE error 1403 encountered
ORA-01403: no data found
EXP-00000: Export terminated unsuccessfully
...........

I want to extract the lines with "ORA-", concatenate and put them in a variable, delimited by "; " (Ex: myvar=ORA-03113: end-of-file on communication channel; ORA-01403: no data found)[

I tried with a script like:
Code:
x=1
while [ $x -le $nrerr ]
do
   if [ $x -ne $nrerr ]; then
         myvar=$err`grep "ORA-" $file| sed -n "$x"p`";"
    else
         myvar=$err`grep "ORA-" $file | sed -n "$x"p`
     fi
     x=$(( $x + 1 ))
done

But the weird thing: it's overwriting my first value in $myvar:
Ex:
Code:
$ myvar = `grep "ORA-" $file | sed -n 2p`
$ echo $myvar
ORA-01403: no data found
$ echo $var"THE END"
THE END03: no data found

Smilie

Thank you.
Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 12-22-2010 at 10:47 AM.. Reason: code tags, please!
# 2  
Old 12-22-2010
Code:
v="$(
  awk -F\; 'END { 
    print r
    }
  /ORA-/ { 
    r = r ? r FS $0 : $0 
     }' infile
  )"

Yse nawk or /usr/xpg4/bin/awk on Solaris.
# 3  
Old 12-22-2010
Code:
 
var=`awk '/^ORA/ {f?f=f ";" $0:f=$0} END { print f }' input_file`

# 4  
Old 12-22-2010
The same result in both cases... variable is overwritten from the start:

Code:
# v="$( awk -F, 'END { print r } /ORA-/ { r = r ? r FS $0 : $0 }' $file )"
 # echo $v
 ,ORA-01403: no data found communication channel

Code:
# var=`awk '/^ORA/ {f?f=f ";" $0:f=$0} END { print f }' $file`
# echo $var
;ORA-01403: no data found communication channel

I've tried with awk, sed, head, tail .. the same result all over again Smilie
# 5  
Old 12-22-2010
Which operating system are you using?
# 6  
Old 12-22-2010
Code:
# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 5.4 (Tikanga)
# awk --version
GNU Awk 3.1.5
# sed --version
GNU sed version 4.1.5

# 7  
Old 12-22-2010
I really don't see how my code could produce an output like the one you posted using GNU awk, but of course, I may be missing something.
Could post your entire script?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem with variables in sed

Hello! I have a problem to insert variables with sed... And I can't find the solution. :confused: I would like to display one/few line(s) between 2 values. This line works well sed -n '/Dec 12 10:42/,/Dec 12 10:47/p' Thoses lines with variables doesn't work and I don't find the... (2 Replies)
Discussion started by: Castelior
2 Replies

2. Shell Programming and Scripting

Concatenate two variables and form the third variable

Hi Guys, I was scratching my head for this for half a day... finally not successful :confused: Following is the problem I have a variable $ var1=123 $ var2-234 $ var3=345 and another Variable $ i=1 Now i wanted to save these into a Variable as shown below for i in 1 2 3 do... (5 Replies)
Discussion started by: ramprabhum
5 Replies

3. Shell Programming and Scripting

Help cannot concatenate Ksh variables ?

Cannot combine these two strings into one line, either as a 3rd variable or echo or printing ? Frustrating. for i in `cat /scripts/pathList.dat` do OldRepo= grep Oldhostname ${i}/.svn/entries | tail -1 NewRepo= grep Oldhostname ${i}/.svn/entries | tail -1 | sed '/Oldhostname/... (41 Replies)
Discussion started by: pcpinkerton
41 Replies

4. Shell Programming and Scripting

concatenate variables

I need to know how to concatenate variables in Debian. I am making a interactive script where it ask the user for info to add a user I pull the first letter from the first middle and last name into individual variables now i want to put them all in one variable so i can put it into useradd command ... (4 Replies)
Discussion started by: HackerSeabass
4 Replies

5. Shell Programming and Scripting

Problem combining two variables into one

Hello, I have a problem combining two variables into one. I did the following: in my env variables i had set PATH_DESTINATION_1=/root/path_one PATH_DESTINATION_2=/root/path_two #!/usr/bin/ksh count=1 count_path=2 while do (3 Replies)
Discussion started by: Eraser
3 Replies

6. Shell Programming and Scripting

Sed with variables problem

I am writing a script with a sed call that needs to use a variable and still have quotations be present in the substitution. Example: sed -i "s/Replacable.\+$/Replaced="root@$VAR"/g" this outputs: where $VAR = place Replaced=root@place and i need Replaced="root@place" ... (2 Replies)
Discussion started by: mcdef
2 Replies

7. Shell Programming and Scripting

how to concatenate values of two variables with an underscore(_) in between

Hi, I'm new to shell programming. I have two variables a and b a=val1 b=val2 could anyone kindly post the shell script to concatenate the values of variable a and b with an underscore(_) in between? The final output should be val1_val2. (8 Replies)
Discussion started by: badrimohanty
8 Replies

8. Shell Programming and Scripting

Problem with variables in awk

Hi, I've a problem with wariables in awk. My example: $ cat test.txt 12|aaaa 13|bbbb 012|cccc 0123|dddd $ cat test.awk $1 == var {print $0} $ cat test.sh /usr/xpg4/bin/awk -F"|" -v var="012" -f test.awk test.txt (5 Replies)
Discussion started by: apresa
5 Replies

9. UNIX for Advanced & Expert Users

Problem in script when using variables

The AppName may be TCS/HCL/SCB. For All the above 3 i ill have exported TCSDIR/HCLDIR/SCBDIR in .profile with some path. i'm cnstruct the path in script and trying to cd $VARIABLE, it shows "not found". Any solution for this....? > AppName="TCS" > echo $AppName TCS >... (4 Replies)
Discussion started by: palsevlohit_123
4 Replies

10. Shell Programming and Scripting

problem with variables

hi all , i wanted to know if someone knows how can i use a variable inside another variable e.g. #!/bin/csh foreach test(1 2 3) set sta_$test = "2" ##now its the problem i want to echo the new var #$sta_$test , each time with anothe num ($test = 1... (2 Replies)
Discussion started by: udi
2 Replies
Login or Register to Ask a Question