CSv2dat file headers and columns order


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting CSv2dat file headers and columns order
# 8  
Old 04-22-2014
Is this what you mean:
replacing my code with your code below?
Code:
BEGIN
{
OFS="\t"
}

NR==1  
{
$7="NUMB";
$8="STRING_COM";
$9="STRING_STATUS"; 
print $0; 
next
} $8 != "c"      
{
$9=$8; 
$8=""
} NF > 9
 {
for (i=10; i<=NF; i++) 
$i=""
}               1

# 9  
Old 04-23-2014
If that delivers that correct result, yes.
# 10  
Old 04-24-2014
CSv2dat file headers and columns order

I have found a solution. it looks like this:

Code:
BEGIN {   FS=","; OFS="\t";   a["ODT"]=1;a["AGE"]=1;a["CDT"]=1;a["CO"]=1;    
 a["SEX"]=1;a["TIME"]=1;a["VALUE"]=1;a["COMMENT"]=1; } 
NR==1 {     $NF=substr($NF,1,length($NF)-1);     for(i=1;i<=NF;i++) if($i in a) a[$i]=i; } {   print $a["ODT"],$a["AGE"],$a["CDT"],$a["CO"],$a["SEX"],$a["TIME"],NR==1?"NUMB":$a["VALUE"],     
NR==1?"STRING_COM"OFS"STRING_STATUS":($a["COMMENT"]!="c"?""OFS$a["COMMENT"]:$a["COMMENT"]); }

still some issues: if I put the column COMMENT after AGE or CDT the "c" character is added in a second line. the second line
contain two tabs and then the "c" character. and if the COMMENT column is at the end and contains character "c", "bcc" the result is putted only on
STRING_STATUS instead of doing the separation > "c" goes to STRING_COM and "bcc" goes to STRING_STATUS
the following cases scenario must be implemented:
Code:
if the VALUE is ":" then NUMB is null
if the VALUE is ":" and COMMENT "c" then NUMB is null and STRING_COM is "c"
if the VALUE is ":" and COMMENT "u" then NUMB is null and STRING_STATUS is "u"
if the VALUE is "14,38" and COMMENT "d" then NUMB is "1438" and STRING(both) is null 
if the VALUE is "14,38" and COMMENT "du" then NUMB is "1438" and STRING_STATUS is "u"
if the VALUE is ":" and COMMENT "cd" then NUMB is null and STRING_COM is "c"
if the VALUE is ":" and COMMENT "bc" then NUMB is null and STRING_COM is "c" and STRING_STATUS is "b"

do you have any suggestion?

---------- Post updated 04-24-14 at 07:47 AM ---------- Previous update was 04-23-14 at 04:56 PM ----------

is anyone who can help me?
I need to implement it asap
thank you in advance

Last edited by grikoss; 04-23-2014 at 06:59 PM.. Reason: wrongly composed
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to compare files and validate order of headers

The below awk verifies the count and order of each text file in the directory. The script does execute and produce output, however the order of the headers are not compared to key. The portion in bold is supposed to do that. If the order of the headers in each text file is the same as key, then... (0 Replies)
Discussion started by: cmccabe
0 Replies

2. UNIX for Advanced & Expert Users

Cannot find logical file format for BSD file headers.

Hi. Unix rookie here. Been looking for a few days for reference documents on how BSD UNIX lays the logical file format onto a disk. Goal is to view/edit with hex editor for data repair. Lots of docs are available for how to use Unix commands (like xxd), but I want to learn the map of how Unix... (4 Replies)
Discussion started by: Chris_top_he_r
4 Replies

3. Shell Programming and Scripting

Re-order columns

I am trying to reorder columns based on a value in a field in the attached file. Thank you :). If $11 is not equal to "unknown", then in a new text file $4, $11, $7, $13 For example, row 24 $11 is not unknown A_16_P39089234, chr10:76765556-76765615, KAT6B, 0.9337 (5 Replies)
Discussion started by: cmccabe
5 Replies

4. Shell Programming and Scripting

copying columns with headers' specific pattern

Hi friends, I have data in tab separated file with headers like this : *sml1 *sml3 *smln7 smfk9 smllf56... Which shell command I should use if i want to extract entire columns that have header names beginning with "*" ? i want to copy these columns into another file. Thanks, (14 Replies)
Discussion started by: jacks
14 Replies

5. Shell Programming and Scripting

Change many columns position/order

Hi everyone, Please some help over here. (I´m using cygwing) I have files with 40 columns and 2000 lines in average. I´m trying to change the order position as follow. Original columns position:... (3 Replies)
Discussion started by: cgkmal
3 Replies

6. Shell Programming and Scripting

Transpose multipe columns to rows and adding headers

Hi, I found the following awk script to transpose multiple (3) columns to multiple rows: #=== BEGIN {FS=","} { for (i=1;i<=NF;i++) { arr=$i; if(nf<= NF) nf=NF; } nr=NR } END { for(i=1;i<=nf;i++) { (8 Replies)
Discussion started by: Gery
8 Replies

7. Shell Programming and Scripting

Merging of files with different headers to make combined headers file

Hi , I have a typical situation. I have 4 files and with different headers (number of headers is varible ). I need to make such a merged file which will have headers combined from all files (comman coluns should appear once only). For example - File 1 H1|H2|H3|H4 11|12|13|14 21|22|23|23... (1 Reply)
Discussion started by: marut_ashu
1 Replies

8. Shell Programming and Scripting

Remove text between headers while leaving headers intact

Hi, I'm trying to strip all lines between two headers in a file: ### BEGIN ### Text to remove, contains all kinds of characters ... Antispyware-Downloadserver.com (Germany)=http://www.antispyware-downloadserver.c om/updates/ Antispyware-Downloadserver.com #2... (3 Replies)
Discussion started by: Trones
3 Replies

9. UNIX for Dummies Questions & Answers

Changing the order of columns in a script

I have the following script: (echo -n `curl http://www.example.com/scores.txt | grep mylocation`; date +%Y%m%d%H%M%S) >> myscores.txt This script works fine, except that it places the timestamp at the end of the file myscores.txt. How do add the timestamp as the first column and then a tab and... (4 Replies)
Discussion started by: figaro
4 Replies

10. Programming

Question on order of headers and WEXITSTATUS

In one of the Unix Programming FAQ's they have the following headers in the program to catch SIGCHLD #include <sys/types.h> /* include this before any other sys headers */ #include <sys/wait.h> /* header for waitpid() and various macros */ #include <signal.h> /* header for signal... (5 Replies)
Discussion started by: frequency8
5 Replies
Login or Register to Ask a Question