Input file:
adc_0123
haa_1000
bcc_520
adc_0150
bcc_290
adc_0112
haa_8000
adc_0139
haa_7000
Output file:
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.
Aia
December 29, 2009, 12:05am
2
Yes, awk would be a good choice. What did you try?
Try:
awk '{ str=$0; if(/^adc_/) print str str; else print "\t"str; }' file
Hi Aia,
This is what I have try before:
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