Printing another column using awk and input data


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Printing another column using awk and input data
# 1  
Old 05-14-2012
Printing another column using awk and input data

Hi, I have data of the following type,

Code:
chr1 234 678 39 852 638 abcd 7895
chr1 526 326 33 887 965 kilj 5849

Now, I would like to have something like this

Code:
chr1 234 678 39 852 638 abcd 7895 <a href="http://unix.com/thread=chr1:234-678">Link</a>
chr1 526 326 33 887 965 kilj 5849 <a href="http://unix.com/thread=chr1:526-326">Link</a>

basically, this is nothing but first column separated by a colon ":" and the second and third columns with a hyphen "-".

My files has around 20000 records.

All helps appreciated. Thanks
# 2  
Old 05-14-2012
Code:
awk '{$0=$0" <a href=\"http://unix.com/thread="$1":"$2"-"$3"\">Link</a>"}1' infile > outfile

This User Gave Thanks to bartus11 For This Post:
# 3  
Old 05-14-2012
Code:
awk '{printf "%s <a href=\"http://unix.com/thread=%s:%s-%s\">Link</a>\n",$0,$1,$2,$3}' infile

This User Gave Thanks to Scrutinizer For This Post:
# 4  
Old 05-14-2012
Thanks scrutinizer and bartus.

But, the last column is being printed without a tab in between.

How do I add a tab between the last and pre-last column?

Thanks
# 5  
Old 05-14-2012
Here?
Code:
awk '{$0=$0"\t<a href=\"http://unix.com/thread="$1":"$2"-"$3"\">Link</a>"}1' infile > outfile

This User Gave Thanks to bartus11 For This Post:
# 6  
Old 05-14-2012
Not sure what you means with the last column. Do you mean this?
Code:
awk '{printf "%s\t<a href=\"http://unix.com/thread=%s:%s-%s\">Link</a>\n",$0,$1,$2,$3}' infile

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

awk to clean up input file, printing both fields

In the f1 file below I am trying to clean it up removing lines the have _tn_ in them. Next, removing the characters in $2 before the ninth /. Then I remove the ID_(digit- always 4). Finally, the charcters after and including the first _. It is curently doing most of it but the cut is removing $1... (5 Replies)
Discussion started by: cmccabe
5 Replies

2. Shell Programming and Scripting

Awk: printing column using for loop

Hello: I've input data: Input data --- 3:60069:C:T 60069 C T 1 0 0 1 0 0 1 0 0 1 0 0 1 --- 3:60079:A:G 60079 A G 1 0 0 0.988 0.012 0 1 0 0 1 0 0 1 --- rs186476240:60157:G:A 60157 G A 1 0 0 1 0 0 1 0 0 1 0 0 1 I edit/make first few columns before numbers (6th column) and want to... (4 Replies)
Discussion started by: genome
4 Replies

3. Open Source

Splitting files using awk and reading filename value from input data

I have a process that requires me to read data from huge log files and find the most recent entry on a per-user basis. The number of users may fluctuate wildly month to month, so I can't code for it with names or a set number of variables to capture the data, and the files are large so I don't... (7 Replies)
Discussion started by: rbatte1
7 Replies

4. Shell Programming and Scripting

Column printing in awk

Experts, i have a following file containing data in following manner. 1 2480434.4 885618.6 0.00 1948.00 40.00 1952.00 ... (6 Replies)
Discussion started by: Amit.saini333
6 Replies

5. Shell Programming and Scripting

awk: printing newline with last column

I was trying to simplify this from what I'm actually doing, but I started getting even more confused so I gave up. Here is the content of my input file: Academic year,Term,Course name,Period,Last name,Nickname 2012-2013,First Semester,English 12,7th Period,Davis,Lucille When I do this: ... (3 Replies)
Discussion started by: nextyoyoma
3 Replies

6. Shell Programming and Scripting

Printing a variable column using awk

Hi everyone, Ok here's the scenario. I have a control file like this. component1,file1,file2,file3,file4,file5 component2,file1,file2,file3,file4,file5I want to do a while loop here to read all files for each component. file_count=2 while ] do file_name=`cat list.txt | grep... (2 Replies)
Discussion started by: The Gamemaster
2 Replies

7. Shell Programming and Scripting

Printing 1st column to lower case using awk

I want to print the 1st field in a comma seperated file to lower case and the rest the case they are. I tried this nawk -F"," '{print tolower($0)}' OFS="," file this converts whole line in to lower case i just want the first column to be converted. The below doesnt work because in... (11 Replies)
Discussion started by: pinnacle
11 Replies

8. Shell Programming and Scripting

Awk not printing the last combined column

nawk -F "|" 'FNR==NR {a=$2 OFS $3 OFS $4 OFS $5 OFS $6;next}\ {if ($5 in a)print $1,"test",$5,a, $2,$3,$4 OFS OFS OFS OFS OFS OFS OFS OFS $2-$3-$4 ; \ else print $1,"Database",$5 OFS OFS OFS OFS OFS OFS $2,$3,$4 OFS OFS OFS OFS OFS OFS OFS OFS $2-$3-$4 }' OFS="|" \ file1 file2 > file3 This... (5 Replies)
Discussion started by: pinnacle
5 Replies

9. Shell Programming and Scripting

Awk+Grep Input file needs to match a column and print the entire line

I'm having problems since few days ago, and i'm not able to make it works with a simple awk+grep script (or other way to do this). For example, i have a input file1.txt: cat inputfile1.txt 218299910417 1172051195 1172070231 1172073514 1183135117 1183135118 1183135119 1281440202 ... (3 Replies)
Discussion started by: poliver
3 Replies

10. Shell Programming and Scripting

AWK - printing certain fields when field order changes in data file

I'm hoping someone can help me on this. I have a data file that greatly simplified might look like this: sec;src;dst;proto 421;10.10.10.1;10.10.10.2;tcp 426;10.10.10.3;10.10.10.4;udp 442;10.10.10.5;10.10.10.6;tcp sec;src;fac;dst;proto 521;10.10.10.1;ab;10.10.10.2;tcp... (3 Replies)
Discussion started by: eric4
3 Replies
Login or Register to Ask a Question