No this is not home work assignment. I had some requirement to restart some of the killed process. my program generate some files(like /tmp/grepd.0003.00049:12:server_read_cb:xxld died) when some process died. So based on the input from the file i have to extract these numbers and manipulate to restart those processes. out File contains following after executing above code
=======
======
so from above out file, i want to extract 03,05,04,07 which is on every fourth row and convert to decimal value, store it in an array.
Moderator's Comments:
Please use CODE tags for sample input, sample output, and code as directed in private mail you received shortly after you posted the 1st message in this thread.
Please note the text marked in red above. You say you want every 4th line from your file. Every 4th line is marked in red. Then you say that you want to extract 4 values (one of which does not appear in the file at all) from those 12 lines.
mahi_mayu069 and RudiC have suggested ways to get the unique values from your output file; but that isn't what you requested. RudiC's code also strips off leading zeros; but you said you wanted to convert the 3rd and 4th characters of a 4 or more digit string treated as octal values to decimal.
I'm going to try once more before I give up on this thread:
Why do you want an array containing 3, 5, 4, and 7 when 4 never appears in your data?
If you want every 4th line from a file, why do you expect to get 4 values from a 12 line file?
Do you really want to extract data from every 4th file from your list of files, or do you want to extract the digits between the 1st and 2nd periods in all of the filenames and process all distinct values you find.
Why do you just want to look at the 3rd and 4th characters from the digits between the 1st and 2nd periods in your filenames?
Why do you want an array? Why not just process the values as you find them?
Please note the text marked in red above. You say you want every 4th line from your file. Every 4th line is marked in red. Then you say that you want to extract 4 values (one of which does not appear in the file at all) from those 12 lines.
mahi_mayu069 and RudiC have suggested ways to get the unique values from your output file; but that isn't what you requested. RudiC's code also strips off leading zeros; but you said you wanted to convert the 3rd and 4th characters of a 4 or more digit string treated as octal values to decimal.
I'm going to try once more before I give up on this thread:
Why do you want an array containing 3, 5, 4, and 7 when 4 never appears in your data?
If you want every 4th line from a file, why do you expect to get 4 values from a 12 line file?
Do you really want to extract data from every 4th file from your list of files, or do you want to extract the digits between the 1st and 2nd periods in all of the filenames and process all distinct values you find.
Why do you just want to look at the 3rd and 4th characters from the digits between the 1st and 2nd periods in your filenames?
Why do you want an array? Why not just process the values as you find them?
1.Why do you want an array containing 3, 5, 4, and 7 when 4 never appears in your data?
sorry it's a typo.
2.If you want every 4th line from a file, why do you expect to get 4 values from a 12 line file? my program generate four instance so i get four values.
3.Do you really want to extract data from every 4th file from your list of files, or do you want to extract the digits between the 1st and 2nd periods in all of the filenames and process all distinct values you find.
I want to extract the digit for example i want to extract 0003 and convert to decimal 3 from this (/tmp/grepd.0003.00049:12:server_read_cb:xxld died)
4.Why do you just want to look at the 3rd and 4th characters from the digits between the 1st and 2nd periods in your filenames?
In 0003 i need decimal coverted 3.
gives 03 and i convert to decimal using
don't confuse with code above code is just example.
5.Why do you want an array? Why not just process the values as you find them?
I've a for loop in my script and further processing of restarting of process based on these values. so i need array for temp storage of values and process it in loop.
Here I've two things
1. After extracting the value from the filename , covert to decimal
2. Store those values in array and process array in loop further restarting of process.
I hope u r clear now with above ans. plz ans how i can i store values in array and process them later.
If I correctly understand what you're trying to do (and I'm not convinced that I do), you can combine your script that produces your data file:
and RudiC's suggestion:
into:
or:
This should work both with ksh and bash. If you want to try either of these on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk, /usr/xpg6/bin/awk, or nawk.
What you do with array is up to you...
This User Gave Thanks to Don Cragun For This Post:
If I correctly understand what you're trying to do (and I'm not convinced that I do), you can combine your script that produces your data file:
and RudiC's suggestion:
into:
or:
This should work both with ksh and bash. If you want to try either of these on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk, /usr/xpg6/bin/awk, or nawk.
What you do with array is up to you...
yes this works fine.. But values are not coming in sorted order
You didn't say anything about needing sorted output before (and you showed us one example where the output you said you wanted was not sorted). But, making several more very wild assumptions based on a pathname sample set of size 1, try:
This User Gave Thanks to Don Cragun For This Post:
Hi, I'm very new to this, so bear with me please.
I want to write a sh script (or if there's a better format please let me know) that allows me to, when I run it, print the date to a file (1.out) take 2 arguments (files a.fa and b.fa), run them with another program, outputting to 2.out, and then... (4 Replies)
Hi, I'm very new to this, so bear with me please.
I want to write a sh script (or if there's a better format please let me know) that allows me to, when I run it, print the date to a file (1.out) take 2 arguments (files a.fa and b.fa), run them with another program, outputting to 2.out, and then... (2 Replies)
Hi,
I have two text files. Need to create a third text file extracting specific data from first two existing files..
Text File 1: Format contains:
SQL*Loader: Release 10.2.0.1.0 - Production on Wed Aug 4 21:06:34 2010
some text ............so on...and somwhere text like:
Record 1:... (1 Reply)
I am attempting to write a housecleaning script that does the following:
1) goes to a specific directory
2) deletes all contents of that directory but a specific directory within it.
So my users all keep and use the Shared directory in OSX. Within /Users/Shared there are also standard named... (1 Reply)
Can anyone please help me in writing a shell script that would check if a particular user(xyz) has logged in, and if yes, the audit daemon needs to be started. When the user logs off the dameon needs to shutdown , and the report needs to be e-mailed to a set of users. (12 Replies)
can anybody help me out in writing the any script (awk,shell or perl script) for incrementing the specific field highlighted below
/{/data/{/assetMetricsList//{1]/dailyCount,........./{/data/{/assetMetricsList//{100]/dailyCount
It should be in below format in oneline seperated by commas
... (1 Reply)
Hi,
I am a new for shell script. i need to write script using the following commands
cd /usres/test
# create directory
mkdir temp+DATE( i need to append date )
#moving files from one directory to this directory(we need to check total files in source and taget)
cd /users/sample
... (2 Replies)
Hello ALL,
I am fresher in Unix . i need help to write small shell script . Please help me unix guru.
I am developing the internal site in my office . the data files are generated in one directory everyday .
I have to write shell script to sort those files and put it is internal site .
... (3 Replies)
I have the following output. I want to write a script to check for
1. waits > 0 on all rowsand Ratio > .0. if true then send email.
=========================
ROLLBACK SEGMENT CONTENTION
=========================
If any ratio is > .01 then more rollback segments are needed
NAME ... (1 Reply)