Getting a number from a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Getting a number from a file
# 1  
Old 09-15-2014
Getting a number from a file

I have a file log.log

HTML Code:
cat log.log
Warning: Using a password on the command line interface can be insecure.
ERROR 1136 (21S01) at line 65: Column count doesn't match value count at row 1
The purpose is at line 65 I want output from other file

for this I am using

gunzip -dc db_sync42.sql.gz | sed -n '65p'

I want the number 65 located in a file log.log, which is to use as variable which I will pass in second file

number = located at second line of log.log file
# 2  
Old 09-15-2014
What have you tried so far?

Can you provide some sample data from the db_sync42.sql.gz file as well as your expected output. Does the log.log file always contain only 2 lines?
# 3  
Old 09-15-2014
Quote:
Originally Posted by pilnet101
What have you tried so far?

Can you provide some sample data from the db_sync42.sql.gz file as well as your expected output. Does the log.log file always contain only 2 lines?
Yes there will be only two lines in log.log
when the error comes It will stop restoration

we can do search a word before colon in log.log

There are some sql commands

Code:
REPLACE INTO `bus_stop` VALUES (21947,'Anand Rao','ARCNEW(aaa)','ಆನಂದ್ ರಾವ್','ಆಋಛ್ಣೇW(ಆಅ)','Approved','Anand Rao@#$@$',12.98041405,77.57240167,-1.00000000,-1.00000000,'Y','ARCNEWaaaaaaaaaaaaaaaa(aaa)','0.0','4.59999','


Last edited by rbatte1; 09-18-2014 at 12:00 PM.. Reason: Changed ICODE tags to just CODE tags
# 4  
Old 09-15-2014
Try
Code:
var=`awk -F'[ :]' '/ERROR/ { print $6 }' log.log`

and then
Code:
gunzip -dc db_sync42.sql.gz | sed -n "$var p"

---------- Post updated at 04:52 PM ---------- Previous update was at 04:47 PM ----------

or with sed:
Code:
var=`sed '1d;s/^.*line //;s/:.*$//' log.log`

# 5  
Old 09-15-2014
Code:
sed -n 's/^ERROR .*line \([^:]*\):.*/\1/p' file

or
Code:
awk '/^ERROR/{print $6+0}' file


--
All in one:
Code:
gunzip -dc db_sync42.sql.gz | awk 'NR==FNR{if(/ERROR/)A[$6+0]; next}FNR in A' log.log -

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Insert content of a file to another file at a line number which is given by third file

Hi friends, here is my problem. I have three files like this.. cat file1.txt ======= unix is best unix is best linux is best unix is best linux is best linux is best unix is best unix is best cat file2.txt ======== Windows performs better Mac OS performs better Windows... (4 Replies)
Discussion started by: Jagadeesh Kumar
4 Replies

2. Shell Programming and Scripting

Splitting XML file on basis of line number into multiple file

Hi All, I have more than half million lines of XML file , wanted to split in four files in a such a way that top 7 lines should be present in each file on top and bottom line of should be present in each file at bottom. from the 8th line actual record starts and each record contains 15 lines... (14 Replies)
Discussion started by: ajju
14 Replies

3. Shell Programming and Scripting

How to count number of files in directory and write to new file with number of files and their name?

Hi! I just want to count number of files in a directory, and write to new text file, with number of files and their name output should look like this,, assume that below one is a new file created by script Number of files in directory = 25 1. a.txt 2. abc.txt 3. asd.dat... (20 Replies)
Discussion started by: Akshay Hegde
20 Replies

4. Shell Programming and Scripting

Replace first number of each line in a file with another number

Hi, I have a set of files in a directory that I have to read and replace the first occurrence of a number with another dummy number. This is what I have so far but it does not seem to work. The files have lot of other data in each row and each data element is separated by ,@, for file in... (13 Replies)
Discussion started by: scorpioraghu
13 Replies

5. Shell Programming and Scripting

Extract a number from a line in a file and sed in another copied file

Dear all, I am trying to extract a number from a line in one file (task 1), duplicate another file (task 2) and replace all instances of the strings 300, in duplicated with the extracted number (task 3). Here is what I have tried so far: for ((k=1;k<4;k++)); do temp=`sed -n "${k}p"... (2 Replies)
Discussion started by: mnaqvi
2 Replies

6. UNIX for Dummies Questions & Answers

How to read contents of a file from a given line number upto line number again specified by user

Hello Everyone. I am trying to display contains of a file from a specific line to a specific line(let say, from line number 3 to line number 5). For this I got the shell script as shown below: if ; then if ; then tail +$1 $3 | head -n $2 else ... (5 Replies)
Discussion started by: grc
5 Replies

7. Shell Programming and Scripting

Number lines of file and assign variable to each number

I have a file with a list of config files numbered on the lefthand side 1-300. I need to have bash read each lines number and assign it to a variable so it can be chosen by the user called by the script later. Ex. 1 some data 2 something else 3 more stuff which number do you... (1 Reply)
Discussion started by: glev2005
1 Replies

8. Shell Programming and Scripting

how to get the data from line number 1 to line number 100 of a file

Hi Everybody, I am trying to write a script that will get some perticuler data from a file and redirect to a file. My Question is, I have a Very huge file,In that file I have my required data is started from 25th line and it will ends in 100th line. I know the line numbers, I need to get all... (9 Replies)
Discussion started by: Anji
9 Replies

9. Shell Programming and Scripting

To read and separate number and words in file and store to two new file using shell

hi, I am a begginer in unix and i want to know how to open a file and read it and separate the numbers & words and storing it in separate files, Using shell scripting. Please help me out for this. Regards S.Kamakshi (2 Replies)
Discussion started by: kamakshi s
2 Replies
Login or Register to Ask a Question