Assign line from file to variable


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Assign line from file to variable
# 1  
Old 07-24-2014
Assign line from file to variable

Hi,

I am new to shell scripting. Need help with the below requirement.

I need help to read a log file and line containing word ORA needs to be captured into a variable and the values of the variable need to be inserted into a table.

For E.g. file test.sql has below error:

ORA-01017: invalid username/password; logon denied

I need to captured this entire line starting from ORA till logon denied. Any error starting from ORA need to be assigned into a variable and to be inserted into a table.

I tried below command:
Code:
awk '/ORA|ORA/ { print }' <  test.log

The above command gave me below output:
Code:
ORA-01017: invalid username/password; logon denied
SP2-0157: unable to CONNECT to ORACLE after 3 attempts, exiting SQL*Plus

I want the first line starting from ORA and that line needs to be inserted into table.

Thank you in advance.
# 2  
Old 07-24-2014
Change:
Code:
awk '/ORA|ORA/ { print }' <  test.log

to:
Code:
awk '/^ORA/ { print }' <  test.log

or:
Code:
awk '/^ORA/ { print }' test.log

or more simply:
Code:
awk '/^ORA/' test.log

or:
Code:
grep '^ORA' test.log

For this, I would recommend using grep instead of awk.
# 3  
Old 07-25-2014
Quote:
Originally Posted by ricsharm
I need help to read a log file and line containing word ORA needs to be captured into a variable and the values of the variable need to be inserted into a table.
Don Cragun told you already how you do select the correct lines. Here is how they are put into a variable:

Code:
typeset VARAIABLE=""

grep '^ORA' /path/to/file |\
while read VARIABLE ; do
     echo "this is the line: >${VARIABLE}<"
done

replace the read-statement with whatever you want to do with the variable.

I hope this helps.

bakunin
# 4  
Old 07-25-2014
Thank you Don Cragun and Bakunin for you help. It worked.

Thanks again.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Assign variable value from file to another with the same name

Hi All, I need to read two config files in a shell script. In that I need to assign a value from one config file to another. I 'm using bash. config_env.txt prefix=tab_ config_properties.txt table_name=${prefix}account So, when I read these two files in a shell script, I need... (6 Replies)
Discussion started by: shash
6 Replies

2. Shell Programming and Scripting

Do While Loop + Read From File + assign line to a variable

Hello, I am using below code for reading from a file and assigning the values to a variable , but it is loosing the value after the loop , please suggest to retain the value of the variable after the loop , while IFS=: read -r line do set $dsc=$line echo 'printing line variable ' $line... (1 Reply)
Discussion started by: ParthThakkar
1 Replies

3. Shell Programming and Scripting

How to read a two files, line by line in UNIX script and how to assign shell variable to awk ..?

Input are file and file1 file contains store.bal product.bal category.bal admin.bal file1 contains flip.store.bal ::FFFF:BADC:CD28,::FFFF:558E:11C5,6,8,2,1,::FFFF:81C8:CA8B,::FFFF:BADC:CD28,1,0,0,0,::FFFF:81C8:11C5,2,1,0,0,::FFFF:81DC:3111,1,0,1,0 store.bal.... (2 Replies)
Discussion started by: veeruasu
2 Replies

4. Shell Programming and Scripting

Assign a variable to number of lines in a file

Hello Gurus, Here is my requirement. I need to find the number of lines in a file and need to assign it to a variable. This is what I did and not wroking. #!/bin/ksh set -xv Src_Path=/mac/dev/Generic/SrcFiles Src_Count=wc -l ${Src_Path}/FILE_JUNE.txt Count_file = $Src_Count | awk -F... (2 Replies)
Discussion started by: thummi9090
2 Replies

5. Shell Programming and Scripting

Assign numbers with decimals from a line to a variable

I am trying to assign a string of numbers with their decimals to a variable. The code reads a file called 'log'. I have not included the entire file since it's huge. The line is: Tagging release with the label program-2.8.114...My code: BUILDNUMFORSIT=$(egrep 'Tagging release with the... (3 Replies)
Discussion started by: sgffgs
3 Replies

6. Shell Programming and Scripting

EXPECT: Assign variable by reading a line of text from a file

Hi All, I have been using a program on windows called AutoKey. My environment at work is Linux and I have been experimenting with expect. Very powerful. I can move my AutoKey scripts to Linux using Expect once I am educated on how to read from a file using Expect. My application would be... (1 Reply)
Discussion started by: quemalr
1 Replies

7. Shell Programming and Scripting

Assign Line Numbers to each line of the file

Hi! I'm trying to assign line numbers to each line of the file for example consider the following.. The contents of the input file are hello how are you? I'm fine. How about you? I'm trying to get the following output.. 1 hello how are you? 2 I'm fine. 3 How about you? ... (8 Replies)
Discussion started by: abk07
8 Replies

8. UNIX for Dummies Questions & Answers

How to assign the content of a file to a variable?

Hi all, I have a problem here. I have a file and let we take the content of the file is just '32' (only a numeric value in that file). Now I need to assign this numeric value ( value in that file) to a variable. Is that possible? If so, can you plz advice me on this? Thanks in... (4 Replies)
Discussion started by: iamgeethuj
4 Replies

9. UNIX for Dummies Questions & Answers

How to Read a config file and Assign to Variable

I have removeConfig file, it contains the dir paths for removing. I need to read line by line and assign to variable. any idea? (1 Reply)
Discussion started by: redlotus72
1 Replies

10. Shell Programming and Scripting

Assign value to a variable in a parameter file

Hi, I have a parameter file and it contains following items $ cat TransactionParams From_Date_Parm=2005-02-25 To_Date_Parm=2005-05-25 Extract_Root_Parm=/detld1/etl/ascential/Ascential/DataStage/Projects/CTI_London/IAM Extract_Type_Parm=Transaction EDW_Database_Parm=hdw_erks... (2 Replies)
Discussion started by: gopskrish
2 Replies
Login or Register to Ask a Question