Print out specific pattern column data


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Print out specific pattern column data
# 1  
Old 12-29-2009
Print out specific pattern column data

Input file:
Code:
adc_0123
haa_1000
bcc_520
adc_0150
bcc_290
adc_0112
haa_8000
adc_0139
haa_7000

Output file:
Code:
adc_0123 adc_0123
              haa_1000
              bcc_520
adc_0150 adc_0150
              bcc_290    
adc_0112 adc_0112
              haa_8000
adc_0139 adc_0139
              haa_7000

I would like to print out again those data that beginning with "adc_" at column 1. It should be able to solve by awk command.
Thanks for any suggestion.
# 2  
Old 12-29-2009
Yes, awk would be a good choice. What did you try?
# 3  
Old 12-29-2009
Try:
Code:
awk '{ str=$0; if(/^adc_/) print str str; else print "\t"str; }' file

# 4  
Old 12-29-2009
Hi Aia,
This is what I have try before:
Code:
awk '$0~/adc_/{print "";t=$1}{for (i=1;1<NF;i++){if ($i~/adc_/){print t,$_} else if ($i ~! /adc_/){print $_}}}' input_file

But it can't get my desired output result.
The dennis's awk code work nice for my problem.
But it got some syntax error

---------- Post updated at 01:05 AM ---------- Previous update was at 01:04 AM ----------

Thanks dennis,
Your awk code work perfectly for my problem.
Thanks again Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

Print all lines between two keyword if a specific pattern exist

I have input file as below I need to check for a pattern and if it is there in file then I need to print all the lines below BEGIN and END keyword. Could you please help me how to get this in AIX using sed or awk. Input file: ABC ******** BEGIN ***** My name is Amit. I am learning unix.... (8 Replies)
Discussion started by: Amit Joshi
8 Replies

3. Shell Programming and Scripting

How to print multiple specific column after a specific word?

Hello.... Pls help me (and sorry my english) :) So I have a file (test.txt) with 1 long line.... for example: isgc jsfh udgf osff 8462 error iwzr 653 idchisfb isfbisfb sihfjfeb isfhsi gcz eifh How to print after the "error" word the 2nd 4th 5th and 7th word?? output well be: 653 isfbisfb... (2 Replies)
Discussion started by: marvinandco
2 Replies

4. UNIX for Dummies Questions & Answers

How to Detect Specific Pattern and Print the Specific String after It?

I'm still beginner and maybe someone can help me. I have this input: the great warrior a, b, c and what i want to know is, with awk, how can i detect the string with 'warrior' string on it and print the a, b, and c seperately, become like this : Warrior Type a b c Im still very... (3 Replies)
Discussion started by: radynaraya
3 Replies

5. Shell Programming and Scripting

Replace column that matches specific pattern, with column data from another file

Can anyone please help with this? I have 2 files as given below. If 2nd column of file1 has pattern foo1@a, find the matching 1st column in file2 & replace 2nd column of file1 with file2's value. file1 abc_1 foo1@a .... abc_1 soo2@a ... def_2 soo2@a .... def_2 foo1@a ........ (7 Replies)
Discussion started by: prashali
7 Replies

6. Programming

Print specific pattern line in c++

Input file: @HWI-BRUNOP1_header_1 GACCAATAAGTGATGATTGAATCGCGAGTGCTCGGCAGATTGCGATAAAC +HWI-BRUNOP1_header_1 TNTTJTTTETceJSP__VRJea`_NfcefbWe Desired output file: >HWI-BRUNOP1_header_1 GACCAATAAGTGATGATTGAATCGCGAGTGCTCGGCAGATTGCGATAAAC >HWI-BRUNOP1_header_2... (10 Replies)
Discussion started by: cpp_beginner
10 Replies

7. Shell Programming and Scripting

print first few lines, then apply regex on a specific column to print results.

abc.dat tty cpu tin tout us sy wt id 0 0 7 3 19 71 extended device statistics r/s w/s kr/s kw/s wait actv wsvc_t asvc_t %w %b device 0.0 133.2 0.0 682.9 0.0 1.0 0.0 7.2 0 79 c1t0d0 0.2 180.4 0.1 5471.2 3.0 2.8 16.4 15.6 15 52 aaaaaa1-xx I want to skip first 5 line... (4 Replies)
Discussion started by: kchinnam
4 Replies

8. UNIX for Dummies Questions & Answers

print a specific column

Hi I want to print column2 if column1 is b with: awk '$1==b {print $2}' infile > outfile infile a 1 b 2 c 3 b 4 e 5 b 6 the outfile is empty. it should look like this: 2 4 6 (2 Replies)
Discussion started by: jdhahbi
2 Replies

9. Shell Programming and Scripting

Question about sort specific column and print other column at the same time !

Hi, This is my input file: ali 5 usa abc abu 4 uk bca alan 6 brazil bac pinky 10 utah sdc My desired output: pinky 10 utah sdc alan 6 brazil bac ali 5 usa abc abu 4 uk bca Based on the column two, I want to do the descending order and print out other related column at the... (3 Replies)
Discussion started by: patrick87
3 Replies

10. Shell Programming and Scripting

Print rows, having pattern in specific column...

Hello all, :) I have a pattern file some what like this, cd003 cd005 cd007 cd008 and input file like this, abc cd001 cd002 zca bca cd002 cd003 cza cba cd003 cd004 zca bac cd004 cd005 zac cba cd005 cd006 acz acb cd006 cd007 caz cab cd007 ... (25 Replies)
Discussion started by: admax
25 Replies
Login or Register to Ask a Question