Sponsored Content
Top Forums Shell Programming and Scripting Organization data based on two conditions applied problem asking... Post 302409393 by patrick87 on Thursday 1st of April 2010 02:55:43 AM
Old 04-01-2010
Organization data based on two conditions applied problem asking...

Input file:
Code:
HS04636  type    header  836     7001    ID=g1
HS04636  type    status  836     1017    Parent=g1.t1
HS04636  type    location        966     1017    ID=g1.t1.cds;Parent=g1.t1
HS04636  type    location        1818    1934    ID=g1.t1.cds;Parent=g1.t1
HS04636  type    status  1818    1934    Parent=g1.t1
HS04636  type    location        2055    2198    ID=g1.t1.cds;Parent=g1.t1
HS04636  type    status  2055    2198    Parent=g1.t1
HS08198  type    header  421     2105    ID=g2
HS08198  type    status  421     582     Parent=g2.t1
HS08198  type    location        445     582     ID=g2.t1.cds;Parent=g2.t1
HS08198  type    location        758     894     ID=g2.t1.cds;Parent=g2.t1
HS08198  type    status  758     894     Parent=g2.t1
.
.

Desired output file:
Code:
HS04636  type    header  836     7001    ID=g1
HS04636  type    status  836     1017    Parent=g1.t1
HS04636  type    location        966     1017    ID=g1.t1.cds;Parent=g1.t1
HS04636  type    status  1818    1934    Parent=g1.t1
HS04636  type    location        1818    1934    ID=g1.t1.cds;Parent=g1.t1
HS04636  type    status  2055    2198    Parent=g1.t1
HS04636  type    location        2055    2198    ID=g1.t1.cds;Parent=g1.t1

HS08198  type    header  421     2105    ID=g2
HS08198  type    status  421     582     Parent=g2.t1
HS08198  type    location        445     582     ID=g2.t1.cds;Parent=g2.t1
HS08198  type    status  758     894     Parent=g2.t1
HS08198  type    location        758     894     ID=g2.t1.cds;Parent=g2.t1
.
.

Two condition to follow:
1. Add a newline before "header" word in column 3;
2. When column 3 is "status" and "location", either one of the content of column 4 and column 5 of them is same. Then must be shown the content of "status" before the content "location" word.
Thanks a lot for any advice to solve this troubles.
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

extract lines based on few conditions

Hi, I need to extract lines based on some conditions as explained below: File format details: notes: 1. each set starts with AAA only 2. number of columns is fixed 3. number of rows per set may vary (as one set is upto DDD - 4 rows) Now, if any BBB's 5th column is blank then then... (4 Replies)
Discussion started by: prvnrk
4 Replies

2. Shell Programming and Scripting

validating a file based on conditions

i have a file in unix in which the records are like this aaa 123 233 aaa 234 222 aaa 242 222 bbb 122 111 bbb 122 123 ccc 124 222 In the output i want only the below records aaa ccc The validation logic is 1st column and 2nd column need to be considered if both columns values are... (8 Replies)
Discussion started by: trichyselva
8 Replies

3. Shell Programming and Scripting

Help with sort data based on descending order problem

Input file 9.99331e-13 8.98451e-65 9.98418e-34 7.98319e-08 365592 111669 74942.9 0 Desired output 365592 111669 74942.9 7.98319e-08 1.99331e-13 6.98418e-34 (2 Replies)
Discussion started by: perl_beginner
2 Replies

4. Shell Programming and Scripting

Help with re-organization data

Input file DATA2.2 POSITION_152486.2 COLUMN689699.2 DATA2.2 ROW00000342066 UNIT00000342313 DATA7.2 POSITION_017891.4 COLUMN060361.4 DATA7.2 ROW00000379319 UNIT00000368623 DATA7.2 ROW00000421241 UNIT00000400736 DATA8.1 POSITION_153254.2 COLUMN694986.2 DATA8.1 ROW00000379288... (1 Reply)
Discussion started by: perl_beginner
1 Replies

5. Shell Programming and Scripting

Report generation based on certain conditions

Hi I recently joined a project where I have been asked to generate a report using shell script accessing UNIX box. I have no idea on how to do it as I am a beginner and learning shell scripts. Suppose I have a XML: Code: ... (3 Replies)
Discussion started by: vat1kor
3 Replies

6. UNIX for Dummies Questions & Answers

Shell script to extract data from csv file based on certain conditions

Hi Guys, 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.... (1 Reply)
Discussion started by: Vivekit82
1 Replies

7. Shell Programming and Scripting

Split File based on different conditions

I need to split the file Conditions: Ignore any record that either starts with 1 or 9 Split the file at position 404 , if position 404 is abc or def then write all the records in a file > File 1 , the remaining records should go in to a file > File 2 Further I want to split the... (7 Replies)
Discussion started by: protech
7 Replies

8. Shell Programming and Scripting

Help with Creating file based on conditions

Can anyone please assist? I have a .txt file(File1.txt) and a property file(propertyfile.txt) . I have to read the vales from the property file and .txt file and create the output file(outputfile.txt) mentioned in the attachment. For each record in .txt file,the below mentioned values shall be... (20 Replies)
Discussion started by: vinus
20 Replies

9. Shell Programming and Scripting

Need script for making files based on some conditions.

Hi All, I have a text file (code_data.txt) with the followig data. AMAR AB123456 XYZ KIRAN CB789 ABC RAJ CS78890 XYZ KAMESH A33535335 ABC KUMAR MD678894 MAT RITESH SR3535355... (26 Replies)
Discussion started by: ROCK_PLSQL
26 Replies
MSSQL_FIELD_SEEK(3)													       MSSQL_FIELD_SEEK(3)

mssql_field_seek - Seeks to the specified field offset

SYNOPSIS
bool mssql_field_seek (resource $result, int $field_offset) DESCRIPTION
Seeks to the specified field offset. If the next call to mssql_fetch_field(3) won't include a field offset, this field would be returned. PARAMETERS
o $result - The result resource that is being evaluated. This result comes from a call to mssql_query(3). o $field_offset - The field offset, starts at 0. RETURN VALUES
Returns TRUE on success or FALSE on failure. EXAMPLES
Example #1 Using mssql_field_seek(3) on the example for mssql_fetch_field(3) <?php // Connect to MSSQL and select the database mssql_connect('MANGOSQLEXPRESS', 'sa', 'phpfi'); mssql_select_db('php'); // Send a select query to MSSQL $query = mssql_query('SELECT * FROM [php].[dbo].[persons]'); // Construct table echo '<h3>Table structure for 'persons'</h3>'; echo '<table border="1">'; // Table header echo '<thead>'; echo '<tr>'; echo '<td>Field name</td>'; echo '<td>Data type</td>'; echo '<td>Max length</td>'; echo '</tr>'; echo '</thead>'; // Dump all fields echo '<tbody>'; for ($i = 0; $i < mssql_num_fields($query); ++$i) { // Fetch the field information, notice the // field_offset parameter is not set. See // the mssql_field_seek call below $field = mssql_fetch_field($query); // Print the row echo '<tr>'; echo '<td>' . $field->name . '</td>'; echo '<td>' . strtoupper($field->type) . '</td>'; echo '<td>' . $field->max_length . '</td>'; echo '</tr>'; // Move the internal seek pointer to the next // row in the result set mssql_field_seek($query, $i + 1); } echo '</tbody>'; echo '</table>'; // Free the query result mssql_free_result($query); ?> SEE ALSO
mssql_fetch_field(3). PHP Documentation Group MSSQL_FIELD_SEEK(3)
All times are GMT -4. The time now is 06:55 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy