Gathering info on one line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Gathering info on one line
# 1  
Old 06-23-2003
Gathering info on one line

Hi all again,

here is the file i am working on :

GREIMBAJ00;BAN_CAV;Loader.sh;2003/06/13;17:04:04
GREIMBAJ00;BAN_CAV;Loader.sh;2003/06/13;17:04:06
GREIMBAJ00;BAN_PAK;Loader.sh;2003/06/13;17:04:11
GREIMBAJ00;BAN_PAK;Loader.sh;2003/06/13;17:04:18
GREIMBAJ00;PER_COT;Loader.sh;2003/06/13;17:04:16
GREIMBAJ00;PER_COT;Loader.sh;2003/06/13;17:04:21
GREIMBAJ00;PER_COT;Traitement.sh;2003/06/13;17:04:18
GREIMBAJ00;PER_COT;Traitement.sh;2003/06/13;17:04:25
GREIMBAJ01;BAN_CAV;Traitement.sh;2003/06/13;17:04:35
GREIMBAJ01;BAN_CAV;Traitement.sh;2003/06/13;17:05:03
GREIMBAJ02;BAN_PAK;Traitement.sh;2003/06/16;09:19:56
GREIMBAJ02;BAN_PAK;Traitement.sh;2003/06/16;09:20:00
GREIMBAJ02;BAN_PAK;Delete.sh;2003/06/16;09:20:03
GREIMBAJ02;BAN_PAK;Delete.sh;2003/06/16;09:20:05
GREIMBAJ04;BAN_LIE;Pretraitement.sh;2003/06/16;09:27:34
GREIMBAJ04;BAN_LIE;Pretraitement.sh;2003/06/16;09:27:37
GREIMBAJ04;BAN_RAV;Traitement.sh;2003/06/16;09:27:39
GREIMBAJ04;BAN_RAV;Traitement.sh;2003/06/16;09:28:23

Here is what i want to do :

When 2 lines are identical (excepting the hour), for instance :

GREIMBAJ00;PER_COT;Traitement.sh;2003/06/13;17:04:18
GREIMBAJ00;PER_COT;Traitement.sh;2003/06/13;17:04:25


i would like to obtain the following result :

GREIMBAJ00;PER_COT;Traitement.sh;2003/06/13;17:04:18;17:04:25

But I dont have any idea on how to make this working...Smilie

Any help would be appreciated !

Thanks

Regards

Howard
# 2  
Old 06-23-2003
FYI, it's easier to follow what's going on if you just continue the thread where you started it:
https://www.unix.com/shell-programming-and-scripting/10475-how-sort-multiples-clolumns-file.html?s=

sort -ut\; -k 1,2 -k 3,4 infile

However, this gives the line with the earliest time, not the latest...
# 3  
Old 06-23-2003
Oups sorry about that...i though this post hadnt any link with the other one....

Anyway, i dont think i had been very clear on my problem....i want to obtain the following result :

GREIMBAJ00;PER_COT;Traitement.sh;2003/06/13;17:04:18;17:04:25

As you can notice, i would like to have the 2 "hour" fileds pasted together and separated by a ";".

As you said, the command you gave only keep the ealiest hour...

Any other idea?

Regards

Howard
# 4  
Old 06-23-2003
You would have to write a script -
read line one - use cut or awk (or some other command to edit the line) to take the first four fields and compare saved line.

(Note, first line in file would not be compared just saved)
read line one
save as compareline
read line two
compare line two against saved line (first four fields only)
if the same, write/print saved line and last field of line two
else
write/print compareline
save line two as compare line
loop

This should work except for when line three is the same as line two...then you will end up with two lines that should have been one line with three different times.

I can't think of a command that will do it on it's own although some of the folks here can do amazing things with sed, awk, and others.
# 5  
Old 06-23-2003
Here's one solution, using awk:
Code:
sort -t\; yourFile > TMP_00

holdField=`head -n 1 TMP_00 | awk -F";" '{print $1";"$2";"$3";"$4}'`

while read LINE
do
 Field=`echo $LINE | awk -F";" '{print $1";"$2";"$3";"$4}'`
 if [ $Field == $holdField ]; then
  allTimes=$allTimes`echo $LINE | awk -F";" '{print ";"$5}'`
 else
  echo $holdField$allTimes >> resultFile
  holdField=$Field
  allTimes=`echo $LINE | awk -F";" '{print ";"$5}'`
 fi
done < TMP_00

echo $holdField$allTimes >> resultFile
rm TMP_00


Last edited by oombera; 06-23-2003 at 04:53 PM..
# 6  
Old 06-24-2003
Smilie That is exactly what i was looking for!

Thank you very much to you!

Regards

HowardSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

2 Loops gathering input

Greetings all, I have came up with some code, to read an input file and generate a list, here is a sample of what I am working with. The variable $USER will be inputted by the person running the utility. do folder=${line%} echo "$folder $USER done < list.txt sample of list.txt- ... (15 Replies)
Discussion started by: jeffs42885
15 Replies

2. Shell Programming and Scripting

Gathering usage statistics

so i have a script that runs across many servers. i'd like to know how many times this script is being used on each server. the only straight forward, non-intrusive way i can think of doing this is to include a line in the script to make a webcall to a central server. and from that central... (9 Replies)
Discussion started by: SkySmart
9 Replies

3. Shell Programming and Scripting

Adding line in a file using info from previous line

I have a shell script that looks something like the following: mysql -uroot db1 < db1.sql mysql -uroot db2 < db2.sql mysql -uroot db3 < db3.sql mysql -uroot db4 < db4.sql .... different db names in more than 160 lines. I want to run this script with nohup and have a status later. So,... (6 Replies)
Discussion started by: MKH
6 Replies

4. Shell Programming and Scripting

HELP: Shell Script to read a Log file line by line and extract Info based on KEYWORDS matching

I have a LOG file which looks like this Import started at: Mon Jul 23 02:13:01 EDT 2012 Initialization completed in 2.146 seconds. -------------------------------------------------------------------------------- -- Import summary for Import item: PolicyInformation... (8 Replies)
Discussion started by: biztank
8 Replies

5. Shell Programming and Scripting

Script to loop line in a file and add info or do echo

I have a record.txt it will update weekly, and it could be 2 lines or more ... it just echo each line to the script san jose,23.34% tampa,2.15% dallas,30.20% seattle,44.29% Unknown,16.72% How do i write a shell script to give me a test.pl or bash file which contain #!/home/perl... (8 Replies)
Discussion started by: sabercats
8 Replies

6. UNIX for Advanced & Expert Users

Gathering data using SAR

Hi everyone, I would like to ask if it is possible to gather SAR data on a specified time. let say yesterdays report, i want to get data at around 12PM and 5PM. thank you. (2 Replies)
Discussion started by: cwiggler
2 Replies

7. HP-UX

HP-UX configuration gathering tool

Hello! I would like to introduce a tool for gathering information on the HP- UX operating system. I would like to hear experts opinions about this utility, its prospects and usefulness. Any feedbacks, suggestions, bug reports, feature requests etc are welcome. The tool project web page:... (0 Replies)
Discussion started by: ahaidukov
0 Replies

8. Shell Programming and Scripting

Data gathering script

I am pretty new at shell scripting, but I managed to make a primative shell script to connect from my webserver (bluehost) to an external data server via ftp or sftp or whatever I need. This script is : #!/bin/sh HOST='ftp.host.com' USER='username' PASSWD='password' FILE='file' ftp -n... (7 Replies)
Discussion started by: mesoeast
7 Replies

9. UNIX for Dummies Questions & Answers

Time difference between each line info....

Hi all, here is a problem, i am having a data in a file of this format, cat filename|grep -ivn edc|tr -s ' ' +|cut -d+ f1,12 1 01:18:38 2007 25 01:43:38 2007 48 01:58:45 2007 71 02:11:02 2007 102 02:19:51 2007 and so on ........ ....... . here... (4 Replies)
Discussion started by: gsp
4 Replies

10. UNIX for Dummies Questions & Answers

Gathering system configuration

Hi there, I have been asked to write a script that gathers enough information on our Sun Solaris machines to be able to rebuild and configure them if they should go pop. My question is does anybody have any suggestions on the files that I need to take a copy of, to ensure that everything is... (4 Replies)
Discussion started by: hcclnoodles
4 Replies
Login or Register to Ask a Question