Generate tabular data based on a column value from an existing data file
Hi,
I have a data file with :
I need to find the first occurring date and the last occurring date for a particular value in column 4 for each combination of column 2 and 3
For example the output from above data should be:
because the value (column 4)=98955 for (column 2)=1 and (column 3)=1 first occurs on date 01/28/2012 and last occurs on date 01/29/2012, after which on 01/30/2012 it changes to 98896,so a new row is added.When a value is the last value in the file, the last occurance date is 99/99/9999.
Not sure whether i could make it clear but is unix shell scripting(with awk maybe) the best way to achieve this or does this need something like perl ?
Last edited by Franklin52; 01-18-2013 at 04:01 AM..
Reason: Please use code tags for data and code samples
I need to find the first occurring date and the last occurring date for a particular value in column 4 for each combination of column 2 and 3
For example the output from above data should be:
because the value (column 4)=98955 for (column 2)=1 and (column 3)=1 first occurs on date 01/28/2012 and last occurs on date 01/29/2012, after which on 01/30/2012 it changes to 98896,so a new row is added.When a value is the last value in the file, the last occurance date is 99/99/9999.
Not sure whether i could make it clear but is unix shell scripting(with awk maybe) the best way to achieve this or does this need something like perl ?
The first line of your expected output ends with 98955, but that value never appears in your data file. I assume this was intended to be 98995 which does appear in your data file with corresponding dates.
I don't understand how you determined the output order of lines in your example output. The following script produces the same data as your expected output (except with 98955 replaced by 98995) but the lines are in a different order:
Note that your input data was sorted by date, but this script will correctly process data presented in any order. The only entry that matters is that the end date of the last entry input is treated specially in the output. If the input data is always sorted by date, this script can be greatly simplified. If you need a specific output order, please describe the order and I'll try again.
As always, if you are using a Solaris/Sun OS system, use /usr/xpg4/bin/awk or nawk, instead of awk.
Last edited by Don Cragun; 01-18-2013 at 09:13 PM..
Reason: update notes about input and output order.
We have the data looks like below in a log file.
I want to generat files based on the string between two hash(#) symbol like below
Source:
#ext1#test1.tale2 drop
#ext1#test11.tale21 drop
#ext1#test123.tale21 drop
#ext2#test1.tale21 drop
#ext2#test12.tale21 drop
#ext3#test11.tale21 drop... (5 Replies)
Hi,
I have a file pk.txt which has pk data in following format
TableName | PK
Employee | id
Contact|name,country
My Output should be
Employee | t1.id=s.id
Contact| t1.name=s.name AND t1.country=s.country
I started of like this:
for LIST in `cat pk.txt` do... (5 Replies)
Hi ,
i am generating some data by firing sql query with connecting to the database by my solaris box.
The below one should be the header line of my excel ,here its coming in separate row.
TO_CHAR(C. CURR_EMP_NO
---------- ---------------
LST_NM... (6 Replies)
Hi all,
I am new to shell script.I need your help to write a shell script.
I need to write a shell script to extract data from a .csv file where columns are ',' separated.
The file has 5 columns having values say column 1,column 2.....column 5 as below along with their valuesm.... (3 Replies)
Hi All
I need to add a column on my existing data file. I know similar posts are there but none of them were meeting my requirement. My input is
1.20 3.44 4.88
5.11 4.99 3.22
1.89 3.89 2.90
Desired output
1 1.20 3.44 4.88
2 5.11 4.99 3.22
3 1.89 3.89 2.90
I will... (2 Replies)
Hi All,
I need to develop a shell script which does sanity check of a data file, as below.
1. For DATE columns, it should check if date is given in proper format or not? For example, if format of date is expected as DD-MON-YYYY HH24:MI:SS and we received the date in formation like DDMMYYYY HH24,... (1 Reply)
Hi all,
I need help to add additional data from file2 to existing data in file 1 using awk, sed or perl. the ID in file 1 should match against field $3 in file2
file1
#this is a new game
ID HR_1
BASE1 30
BASE2 37
DETAIL No
TYPE L
@@
ID HR_10
BASE1 6030
BASE2 ... (4 Replies)
Hi,
Could anyone help me in changing a tabular format output to comma seperated file pls in K-sh. Its very urgent.
E.g : username empid
------------------------
sri 123
to
username,empid
sri,123
Thanks,
Hema:confused: (2 Replies)