Print column based on pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Print column based on pattern
# 1  
Old 12-29-2015
Linux Print column based on pattern

Hi all,

how print on columns when contain un pattern specific,

e.g.
Code:
$cat file1


3234 234 2323
number1 number2 number3
123 242 124
124 number2 324
424 543 626
number1 3463 234
534 345 number3
6756 345 2352
334 345 234

need output file1 way

Code:
number1     number2          number3
3234               234                   2323
123                 242                    124
124                 543                     324
424                3463                  626
534                 345                     234
6756                345                     2352
334                 345                     234

thank you,

Last edited by Scrutinizer; 12-29-2015 at 12:37 PM.. Reason: CODE tags !!!! + Changed code tags to code tags + new code tags after OP changed it!
# 2  
Old 12-29-2015
Please explain in English what you are trying to do. I don't see a clear algorithm that fits the transformation of your sample input to the output you want.
# 3  
Old 12-29-2015
Perhaps he means something like this?

Code:
awk '
  {
    for(j=1; j<=NF; j++) {
      if($j~/[[:alpha:]]/)
        H[j]=$j
      else 
        A[++C[j],j]=$j
    }
  } 
  END {
    n=NF
    for(j=1; j<=n; j++)
      $j=H[j]
    print
    for(i=1; i<=C[1]; i++) {
      for(j=1; j<=n; j++) 
        $j=A[i,j]
      print
    }
  }
' OFS='\t' file

Code:
number1 number2 number3
3234    234     2323
123     242     124
124     543     324
424     3463    626
534     345     234
6756    345     2352
334     345     234

This User Gave Thanks to Scrutinizer For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find matched pattern and print all based on certain conditions

Hi, I am trying to extract data based on certain conditions. My sample input file as below:- lnc-2:1 OnePiece tra_law 500 688 1 . . g_id "R792.8417"# tra_law_id "R792.8417.1"# g_line "2.711647"# KM "8.723820"# lnc-2:1 OnePiece room 500 510 1 . . g_id "R792.8417"# tra_law_id "R792.8417.1"#... (7 Replies)
Discussion started by: bunny_merah19
7 Replies

2. Shell Programming and Scripting

To print diamond asterisk pattern based on inputs

I have to print the number of stars that increases on each line from the minimum number until it reaches the maximum number, and then decreases until it goes back to the minimum number. After printing out the lines of stars, it should also print the total number of stars printed. I have tried... (13 Replies)
Discussion started by: rohit_shinez
13 Replies

3. UNIX for Beginners Questions & Answers

If pattern in column 3 matches pattern in column 2 (any row), print value in column 1

Hi all, I have searched and searched, but I have not found a solution that quite fits what I am trying to do. I have a long list of data in three columns. Below is a sample: 1,10,8 2,12,10 3,13,12 4,14,14 5,15,16 6,16,18 Please use code tags What I need to do is as follows: If a... (4 Replies)
Discussion started by: bleedingturnip
4 Replies

4. Shell Programming and Scripting

Print the column content based on the header

i have a input of csv file as below but the sequence of column get changed. I,e it is not necessary that name comes first then age and rest all, it may vary. name,age,marks,roll,section kevin,25,80,456,A Satch,23,56,789,B Meena,24,78,H245,C So i want to print that column entires which... (12 Replies)
Discussion started by: millan
12 Replies

5. Shell Programming and Scripting

print the whole row in awk based on matched pattern

Hi, I need some help on how to print the whole data for unmatched pattern. i have 2 different files that need to be checked and print out the unmatched patterns into a new file. My sample data as follows:- File1.txt Id Num Activity Class Type 309 1.1 ... (5 Replies)
Discussion started by: redse171
5 Replies

6. Shell Programming and Scripting

grep based on pattern in a line and print the column before that

$ cat file.log Message Number = : Sending message 10:50:16^|^reqhdr.dummyid^=^02^|^reqhdr.timezone^=^GMT+05:30^|^DUMMYREQUEST^=^BH||||||||||||||||||$BD|OL|C|V||DummyAcctNo|02||24/12/2011|ST_DDM|DDM||||||||reqUUID110612105016$BT||||||||||||||||||$] Length I have the above line in the... (4 Replies)
Discussion started by: kalidass
4 Replies

7. Shell Programming and Scripting

need to remove duplicates based on key in first column and pattern in last column

Given a file such as this I need to remove the duplicates. 00060011 PAUL BOWSTEIN ad_waq3_921_20100826_010517.txt 00060011 PAUL BOWSTEIN ad_waq3_921_20100827_010528.txt 0624-01 RUT CORPORATION ad_sade3_10_20100827_010528.txt 0624-01 RUT CORPORATION ... (13 Replies)
Discussion started by: script_op2a
13 Replies

8. Shell Programming and Scripting

Print a pattern between the xml tags based on a search pattern

Hi all, I am trying to extract the values ( text between the xml tags) based on the Order Number. here is the sample input <?xml version="1.0" encoding="UTF-8"?> <NJCustomer> <Header> <MessageIdentifier>Y504173382</MessageIdentifier> ... (13 Replies)
Discussion started by: oky
13 Replies

9. Shell Programming and Scripting

Q: print a column based on the uniqe value of another

Hi there, If I have the following: and want to print the first column based on the uniqe value of the second column, so the output would be something like: how would I do that, using AWK and the piping technique? Thanks in advance (12 Replies)
Discussion started by: Abdulelah
12 Replies

10. Shell Programming and Scripting

Need to print last column based on the value of first 2 colums

Hi Everybody. I need an urgent help, it would be great if somebody will help me out in this regard. See below sample file 1525 805 26 2036 219644. 2598293. 1525 805 126 2327 1525 805 226 ... (6 Replies)
Discussion started by: syahmed
6 Replies
Login or Register to Ask a Question