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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reformating table + 2 output files 1

Status
Not open for further replies.

rossyeperez

Technical User
Feb 1, 2007
15
MX
I have the following kind of file :

DEPTH cdccd aaa dccc cdfd
xxxx ccccc xxxx vvvv
xxxx ccccc xxxx xxxx
xxxxx vvvv xxxx
xxxx ffff ssss qqqq
DEPTH xxx xxx ccc xxx yy zz vvvvv
1 xxx-sss 2 3 -4 5 6 xxx-sss
2 ddd-ppp 3 -4 -5 6 7 xxx-sss
3 ccc-ppp -4 5 -6 7 8 xxx-sss
4 vvv-ooo 5 6 -7 8 0 xxx-sss

I would like to get two file outputs

one file that print all the information before of second DEPTH row

DEPTH cdccd aaa dccc cdfd
xxxx ccccc xxxx vvvv
xxxx ccccc xxxx xxxx
xxxxx vvvv xxxx
xxxx ffff ssss qqqq

and the second file with all the information after of second DEPTH row but deleting columns with character except the columns with negative values :

DEPTH xxx ccc xxx yy zz
1 2 3 -4 5 6
2 3 -4 -5 6 7
3 -4 5 -6 7 8
4 5 6 -7 8 0

keeping the row with the second DEPTH and deleting the correspond column that were erased in the table.

Thanks
Rossy

 
Hi

Code:
awk '$1=="DEPTH"{d++}d==1{print>"[green][i]/output/file1[/i][/green]"}d==2{print$1,$3,$4,$5,$6,$7>"[green][i]/output/file2[/i][/green]"}' /input/file
Tested with [tt]gawk[/tt].

Feherke.
 
thanks :)

But if I don't know how many column I will have inside the file and the columns with characters is not all the time in the same position
 
Hi

Rossy said:
the columns with characters is not all the time in the same position
Ok. Then I hope the columns with characters will have characters in every row.
Code:
awk '$1=="DEPTH"{d++}d==1{print>"[green][i]/output/file1[/i][/green]"}$1=="DEPTH"&&d==2{h=$0;getline;for(i=1;i<=NF;i++)n[i]=$i==$i+0
;f=$0;$0=h;printn();$0=f;printn()}d==2{printn()}function printn(){for(i=1;i<=NF;i++)if(n[i])printf$i OFS>"[green][i]/output/file2[/i][/green]";print"">"[green][i]/output/file2[/i][/green]"}' /input/file
Tested with [tt]gawk[/tt].

Feherke.
 


Thanks

in the second output file I get a file with the following output :

123-45623-4-5673-45-678456-780


Regards
Rossy
 
Hi

For the input you gave us I get the following two files
[tt]
[highlight navajowhite] /output/file1 [/highlight]
DEPTH cdccd aaa dccc cdfd
xxxx ccccc xxxx vvvv
xxxx ccccc xxxx xxxx
xxxxx vvvv xxxx
xxxx ffff ssss qqqq

[highlight navajowhite] /output/file2 [/highlight]
DEPTH xxx ccc xxx yy zz
1 2 3 -4 5 6
1 2 3 -4 5 6
2 3 -4 -5 6 7
3 -4 5 -6 7 8
4 5 6 -7 8 0
[/tt]
With [tt]gawk[/tt] and [tt]mawk[/tt] on Linux, [tt]gawk[/tt] on CygWin and [tt]awk95[/tt] on Windows.

What are you using ?

Feherke.
 
thanks I used awk95 on windows and the program work

Rossy
 
Feherke,

I have another question related with the same program .. when I have the following kind of file and the firts column before the second DEPTH row corespond
with the SECOND DEPTH row values in horizontal like this :

DEPTH cdccd aaa dccc cdfd
xxx ccccc xxxx vvvv
xxx ccccc xxxx xxxx
ccc vvvv xxxx
xxx dddd ddd dddd
yy ffff ssss qqqq
zz cc cc ccc ccc
vvvvv xxx xxx xxx xxx
DEPTH xxx xxx ccc xxx yy zz vvvvv
1 xxx-sss 2 3 -4 5 6 xxx-sss
2 ddd-ppp 3 -4 -5 6 7 xxx-sss
3 ccc-ppp -4 5 -6 7 8 xxx-sss
4 vvv-ooo 5 6 -7 8 0 xxx-sss

I would like to get one file when I erase the columns with character after the second DEPTH row that erase in the vertical firts row the same rows equivalent to the were eliminated horizontally like this :


DEPTH cdccd aaa dccc cdfd
xxx ccccc xxxx xxxx
ccc vvvv xxxx
xxx dddd ddd dddd
yy ffff ssss qqqq
zz cc cc ccc ccc
DEPTH xxx ccc xxx yy zz
1 2 3 -4 5 6
2 3 -4 -5 6 7
3 -4 5 -6 7 8
4 5 6 -7 8 0



 
Hi

Sorry, I do not understand the relation between removed data and ... no idea what. When should they be removed ?

Could you please mark with colors on your sample data the fields/rows/columns involved in the condition(s) of removal ? ?

Feherke.
 
Column in Rose color have the same values in the same order that the row in rose color horizontally:

[highlight #FF99FF]DEPTH[/highlight] cdccd aaa dccc cdfd
[highlight #FF99FF]xxx[/highlight] ccccc xxxx vvvv
[highlight #FF99FF]xxx[/highlight] ccccc xxxx xxxx
[highlight #FF99FF]ccc[/highlight] vvvv xxxx
[highlight #FF99FF]xxx[/highlight] dddd ddd dddd
[highlight #FF99FF]yy[/highlight] ffff ssss qqqq
[highlight #FF99FF]zz[/highlight] cc cc ccc ccc
[highlight #FF99FF]vvvvv[/highlight] xxx xxx xxx xxx
[highlight #FF99FF]DEPTH xxx xxx ccc xxx yy zz vvvvv[/highlight]
1 xxx-sss 2 3 -4 5 6 xxx-sss
2 ddd-ppp 3 -4 -5 6 7 xxx-sss
3 ccc-ppp -4 5 -6 7 8 xxx-sss
4 vvv-ooo 5 6 -7 8 0 xxx-sss

as the last program that you provide me that eliminate in the second output file all the columns with charaters , I would like to get a third file that due the column mark in rose corresponding with the table headers below , when the characters columns are eliminated the rows that correspondin with the table header will be eliminated too .. I will put in Red color the columns and rows that I need eliminate:

DEPTH cdccd aaa dccc cdfd
xxx ccccc xxxx vvvv
xxx ccccc xxxx xxxx
ccc vvvv xxxx
xxx dddd ddd dddd
yy ffff ssss qqqq
zz cc cc ccc ccc
vvvvv xxx xxx xxx xxx
DEPTH xxx xxx ccc xxx yy zz vvvvv
1 xxx-sss 2 3 -4 5 6 xxx-sss
2 ddd-ppp 3 -4 -5 6 7 xxx-sss
3 ccc-ppp -4 5 -6 7 8 xxx-sss
4 vvv-ooo 5 6 -7 8 0 xxx-sss
 
Hi Feherke,

can you get understand mi last question??
Please let me know if you need any additional information.

Thanks
Rossy
 
Hi

Is due that this lines in the first column have the same values as the header columns with charaters that in the last program are erased and normally the first column before the second DEPTH have the same values (vertically) equivalents with the row values on the second DEPTH... and I would like when the second program that you made get erased columns with charaters at same time get erase the lines before the second DEPTH that have equivalence with the columns headers on the second DEPTH row tha was erased.



DEPTH cdccd aaa dccc cdfd
xxx ccccc xxxx vvvv
xxx **(1) ccccc xxxx xxxx
ccc vvvv xxxx
xxx dddd ddd dddd
yy ffff ssss qqqq
zz cc cc ccc ccc
vvvvv **(2)xxx xxx xxx xxx
DEPTH xxx **(1) xxx ccc xxx yy zz vvvvv**(2)
1 xxx-sss 2 3 -4 5 6 xxx-sss
2 ddd-ppp 3 -4 -5 6 7 xxx-sss
3 ccc-ppp -4 5 -6 7 8 xxx-sss
4 vvv-ooo 5 6 -7 8 0 xxx-sss

**(1) the second line firts column before second DEPTH
have same value with the header of the $2 with character on second DEPTH row.


**(2) the second line firts column before second DEPTH
have same value with the header of the $8 with character on second DEPTH row.

Rossy

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top