Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search in a file

Status
Not open for further replies.

RicardoPereira

Programmer
Jun 3, 2003
255
PT
Hi,

I'am trying to develop a script to backup my data and logs of informix. After backup i put the output in a file. Then what i want is serach the number of the log in the output file and rename the file "tdata.dat" to "tdata_6542.dat" (this is an example). How can i search this value ?? It is always different. I think it is always in the line 10 and the number begins always after the text "Log: "

Any suggestion ??

Thanks
Ricardo
 
sample file, pls

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Here is a sample


Please mount tape 1 on mb_rs1:/dev/rmt2 and press Return to continue ...
10 percent done.
20 percent done.
30 percent done.
40 percent done.
50 percent done.

Please label this tape as number 1 in the arc tape sequence.
This tape contains the following logical logs:

15891
 
Something like this ?
log=`awk '
/logical logs:/{++l}
NF==1 && l{print $1;exit}
' tdata.dat` && mv tdata.dat tdata_$log.dat

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Could you please explain what means each line of the code you suggest ?
 
1) The skeleton is:
log=`awk 'awk program' tdata.dat` && mv tdata.dat tdata_$log.dat
set the variable log to the value found in tdata.dat and use it to rename the file
2) Now the awk program:
/logical logs:/{++l}
each time we found the test pattern, increment a counter
NF==1 && l{print $1;exit}
if the current line is only one field and if the test pattern is already found then print the field and stop processing
BTW, does this works within your environment ?

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Code:
let NR=`head -10 tdata.log | tail -1 | sed 's/[\t ]*//g'`
echo tdata_$NR.dat
mv tdata.dat tdata_$NR.dat

let:  set a numeric variable
`` :  execute as a whole
head: display only the first -X lines of a file
tail: display only the last -X lines of a file
sed:  see: man sed - manipulate a String, strip off tabulator  
      and or blank
echo: might be removed
mv:   move a file
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top