Sponsored Content
Top Forums Shell Programming and Scripting Swapping columns in specific blocks Post 302963503 by RavinderSingh13 on Thursday 31st of December 2015 02:50:46 PM
Old 12-31-2015
Hello jypark22,

Following may help you in same.
Code:
awk -vs1="\$path" -vs2="// from: in11" -vs3="// to: out432" -vs4="\$name "test_" ;" -vs5="\$cycle 1 ;" -vs6="\$slack -0.130978 ;" -vs7="\$transition {" -vs8="\"" '{VAR=s1 "\n" s2 "\n" s3 "\n" s4  "\n" s5 "\n" s6 "\n" s7};/ Point/{getline;getline;getline;while($0 !~ /Endpoint/){if($0 ~ /data arrival time/ || $0 ~ /Path is unconstrained/ || $0 ~ /^$/){;next};$1=s8 $1 s8;if($5 ~ /r/){$5="v"};if($5 ~ /f/){$5="^"};sub($3,";");sub($4,"//");E=$NF;$NF=$2;$2=E;S=S?S ORS $0:$0;getline}};/ Endpoint/{if(S){d++;sub(/test_/,"&" d,VAR);print VAR ORS S ORS " }" ORS "}" ORS;S=""}} END{d++;sub(/test_/,"&" d,VAR);print VAR ORS S ORS " }" ORS "}"}'   Input_file

Output will be as follows.
Code:
$path
// from: in11
// to: out432
$name test_1 ;
$cycle 1 ;
$slack -0.130978 ;
$transition {
"in11" v ; // (in)
"Ckt432/A[7]" v ; // (TopLevel432b)
"Ckt432/M1/A[7]" v ; // (PriorityA)
"Ckt432/M1/U7/Y" ^ ; // (INVX1_RVT)
"Ckt432/M5/U12/Y" v ; // (OA21X1_RVT)
"Ckt432/M5/Chan[3]" v ; // (DecodeChan)
"Ckt432/Chan[3]" v ; // (TopLevel432b)
"out421" v ; // (out)
 }
}
 $path
// from: in11
// to: out432
$name test_2 ;
$cycle 1 ;
$slack -0.130978 ;
$transition {
"in37" v ; // (in)
"Ckt432/A[5]" v ; // (TopLevel432b)
"Ckt432/M1/A[5]" v ; // (PriorityA)
"Ckt432/M1/U8/Y" ^ ; // (INVX1_RVT)
"Ckt432/M1/U13/Y" v ; // (NAND2X0_RVT)
"Ckt432/M5/U12/Y" v ; // (OA21X1_RVT)
"Ckt432/M5/Chan[3]" v ; // (DecodeChan)
"Ckt432/Chan[3]" v ; // (TopLevel432b)
"out421" v ; // (out)
 }
}

EDIT: Adding a non one-liner form for same solution too now.
Code:
awk -vs1="\$path" -vs2="// from: in11" -vs3="// to: out432" -vs4="\$name "test_" ;" -vs5="\$cycle 1 ;" -vs6="\$slack -0.130978 ;" -vs7="\$transition {" -vs8="\"" '{
VAR=s1 "\n" s2 "\n" s3 "\n" s4  "\n" s5 "\n" s6 "\n" s7};
/ Point/{
                getline;
                getline;
                getline;
                while($0 !~ /Endpoint/){
                                        if($0 ~ /data arrival time/ || $0 ~ /Path is unconstrained/ || $0 ~ /^$/){;
                                                                                                                        next
                                                                                                                 }
                ;$1=s8 $1 s8;
                if($5 ~ /r/)           {
                                        $5="v"
                                       };
                if($5 ~ /f/)           {
                                        $5="^"
                                       };
                sub($3,";");
                sub($4,"//");
                E=$NF;
                $NF=$2;
                $2=E;
                S=S?S ORS $0:$0;
                getline
                                       }
        };
/ Endpoint/{
                if(S)                  {
                                        d++;
                                        sub(/test_/,"&" d,VAR);
                                        print VAR ORS S ORS " }" ORS "}" ORS;
                                        S=""
                                       }
           }
END        {
                d++;
                sub(/test_/,"&" d,VAR);
                print VAR ORS S ORS " }" ORS "}"
           }'  Input_file

Output will be as follows.
Code:
$path
// from: in11
// to: out432
$name test_1 ;
$cycle 1 ;
$slack -0.130978 ;
$transition {
"in11" v ; // (in)
"Ckt432/A[7]" v ; // (TopLevel432b)
"Ckt432/M1/A[7]" v ; // (PriorityA)
"Ckt432/M1/U7/Y" ^ ; // (INVX1_RVT)
"Ckt432/M5/U12/Y" v ; // (OA21X1_RVT)
"Ckt432/M5/Chan[3]" v ; // (DecodeChan)
"Ckt432/Chan[3]" v ; // (TopLevel432b)
"out421" v ; // (out)
 }
}
$path
// from: in11
// to: out432
$name test_2 ;
$cycle 1 ;
$slack -0.130978 ;
$transition {
"in37" v ; // (in)
"Ckt432/A[5]" v ; // (TopLevel432b)
"Ckt432/M1/A[5]" v ; // (PriorityA)
"Ckt432/M1/U8/Y" ^ ; // (INVX1_RVT)
"Ckt432/M1/U13/Y" v ; // (NAND2X0_RVT)
"Ckt432/M5/U12/Y" v ; // (OA21X1_RVT)
"Ckt432/M5/Chan[3]" v ; // (DecodeChan)
"Ckt432/Chan[3]" v ; // (TopLevel432b)
"out421" v ; // (out)
 }
}

Thanks,
R. Singh

Last edited by RavinderSingh13; 12-31-2015 at 04:25 PM.. Reason: Added a non one-liner form for solution now.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Mean of the specific columns

I have a input file that has some common values in 1st,2nd and 3rd columns. 4th and 5th are different. Now I would like to print the mean of the fourth column of similar values in 1st.2nd and 3rd columns along with all the values in 5th column. input NM_0 1.22 CR5 0.4 n_21663... (10 Replies)
Discussion started by: repinementer
10 Replies

2. UNIX for Dummies Questions & Answers

Convert 512-blocks to 4k blocks

I'm Unix. I'm looking at "df" on Unix now and below is an example. It's lists the filesystems out in 512-blocks, I need this in 4k blocks. Is there a way to do this in Unix or do I manually convert and how? So for container 1 there is 7,340,032 in size in 512-blocks. What would the 4k block be... (2 Replies)
Discussion started by: rockycj
2 Replies

3. Shell Programming and Scripting

how to split this file into blocks and then send these blocks as input to the tool called Yices?

Hello, I have a file like this: FILE.TXT: (define argc :: int) (assert ( > argc 1)) (assert ( = argc 1)) <check> # (define c :: float) (assert ( > c 0)) (assert ( = c 0)) <check> # now, i want to separate each block('#' is the delimeter), make them separate files, and then send them as... (5 Replies)
Discussion started by: paramad
5 Replies

4. Shell Programming and Scripting

Help swapping columns with AWK

Hi! Im trying to swap 2 columns in a file.The file format is: 'ColumnA','ColumnB' 'A1','A2' 'B1','B2' 'C1','C2' I tried to solve this using AWK, when I run this command: awk 'BEGIN {FS=OFS=","} {temp=$1; $1=$2; $2=temp} {print}' InFile.csv >> Outfile.csv What I get is this: ... (5 Replies)
Discussion started by: RedSpyder
5 Replies

5. UNIX for Dummies Questions & Answers

Display blocks containing specific pattern

Hi, I have a file containing multiple entries. Each block starts with <BEGIN and ends with <END. Sample data is given below <BEGIN IMSI=095001202630; MSISDN=00145132916; DEFCALL=TS11; CURRENTNAM=BOTH; CAT=COMMON; TBS=TS11&TS12&TS21&TS22; CARDTYPE=SIM; ... (2 Replies)
Discussion started by: krabu
2 Replies

6. UNIX for Dummies Questions & Answers

Swapping the columns of a text file for a subset of rows

Hi, I'd like to swap the columns 1 and 2 of a space-delimited text file but only for the first 1000 rows. How do I go about doing that? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

7. Shell Programming and Scripting

Can't figure out how to find specific characters in specific columns

I am trying to find a specific set of characters in a long file. I only want to find the characters in column 265 for 4 bytes. Is there a search for that? I tried cut but couldn't get it to work. Ex. I want to find '9999' in column 265 for 4 bytes. If it is in there, I want it to print... (12 Replies)
Discussion started by: Drenhead
12 Replies

8. Shell Programming and Scripting

Row blocks to column blocks

Hello, Searched for a while and found some "line-to-column" script. My case is similar but with multiple fields each row: S02 Length Per S02 7043 3.864 S02 54477 29.89 S02 104841 57.52 S03 Length Per S03 1150 0.835 S03 1321 0.96 S03 ... (9 Replies)
Discussion started by: yifangt
9 Replies

9. UNIX for Dummies Questions & Answers

Printing lines with specific strings at specific columns

Hi I have a file which is tab-delimited. Now, I'd like to print the lines which have "chr6" string in both first and second columns. Could anybody help? (3 Replies)
Discussion started by: a_bahreini
3 Replies

10. Shell Programming and Scripting

Modify blocks of text by printing missing columns

Hi Experts, I have a problem where I want to print missing columns (3,4) within a block of text. Each block is separated by "###". Some rows have missing column 3 and 4 which should be same as the previous value in column 3 and 4. The file is space delimited. For example: INPUT ###... (5 Replies)
Discussion started by: mira
5 Replies
All times are GMT -4. The time now is 03:22 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy