Print a column with the name of the output file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Print a column with the name of the output file
# 1  
Old 03-06-2012
Print a column with the name of the output file

I have n files and I am using cat to combine them in to one.
Before that simply add the name of the output file to 4th column and then print the output. Is it possible ?


input1

Code:
chr    start    end    name    0    +    key

input2

Code:
chr    start    end    name    0    +    key

inputn
Code:
chr    start    end    name    0    +    key

print a column with the name of the output file
Code:
chr    start    end    name_input1    0    +    key
chr    start    end    name_input2    0    +    key
chr    start    end    name_inputn    0    +    key

# 2  
Old 03-06-2012
Code:
awk '{$4=sprintf("%s_%s",$4,FILENAME);print}' input*

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Convert rows to column and print output in required format

Hi All, i am trying to print the solaris 11 packages in below required format, But i am unable to do that. Current ouput : root@abc# pkginfo -l | egrep '(BASEDIR|NAME|VERSION)' | awk '{print}' NAME: QLogic 570x/571x Gigabit Ethernet Driver VERSION: 11.11,REV=2009.11.11 ... (7 Replies)
Discussion started by: balu1234
7 Replies

2. UNIX for Beginners Questions & Answers

Need to print nth till last column of ls output using sed

I wish to print first, third and sixth till the last column from the output of ls command ls -ltr /app/deploy.yml -rw-rw-r-- 1 user1 dba 27342 Aug 28 10:17 /app/deploy.yml Desired Output: Below command gives me the desired output. ls -ltr /app/deploy.yml | awk '{$2=$4=$5=""; print... (6 Replies)
Discussion started by: mohtashims
6 Replies

3. UNIX for Beginners Questions & Answers

Compare 1st column from 2 file and if match print line from 1st file and append column 7 from 2nd

hi I have 2 file with more than 10 columns for both 1st file apple,0,0,0...... orange,1,2,3..... mango,2,4,5..... 2nd file apple,2,3,4,5,6,7... orange,2,3,4,5,6,8... watermerlon,2,3,4,5,6,abc... mango,5,6,7,4,6,def.... (1 Reply)
Discussion started by: tententen
1 Replies

4. Shell Programming and Scripting

awk Print New Column For Every Two Lines and Match On Multiple Column Values to print another column

Hi, My input files is like this axis1 0 1 10 axis2 0 1 5 axis1 1 2 -4 axis2 2 3 -3 axis1 3 4 5 axis2 3 4 -1 axis1 4 5 -6 axis2 4 5 1 Now, these are my following tasks 1. Print a first column for every two rows that has the same value followed by a string. 2. Match on the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

5. UNIX for Dummies Questions & Answers

Print each output of loop in new column using awk or shell

I have this output from a loop a11 1,2 3,4 5,6 7,8 12,8 5,4 3,6 a12 10,11 12,13 15,18 20,22 a13 ... (3 Replies)
Discussion started by: maryre89
3 Replies

6. Shell Programming and Scripting

Awk script to run a sql and print the output to an output file

Hi All, I have around 900 Select Sql's which I would like to run in an awk script and print the output of those sql's in an txt file. Can you anyone pls let me know how do I do it and execute the awk script? Thanks. (4 Replies)
Discussion started by: adept
4 Replies

7. Shell Programming and Scripting

comparing column of two different files and print the column from in order of 2nd file

Hi friends, My file is like: Second file is : I need to print the rows present in file one, but in order present in second file....I used while read gh;do awk ' $1=="' $gh'" {print >> FILENAME"output"} ' cat listoffirstfile done < secondfile but the output I am... (14 Replies)
Discussion started by: CAch
14 Replies

8. Shell Programming and Scripting

How do you print column 1 from comm output to a file?

Hi guys, I have a script, which after running for 20 minutes, produces a bunch of IPs. Due to a DHCP scope, some of these IPs are not useable, so I would like to eliminate them from the final list. I have used comm to do this, but am unable to extract the first column, and redirect it to a... (1 Reply)
Discussion started by: Bloke
1 Replies

9. Shell Programming and Scripting

4 column tsv file, output 1 specific column

Hello all siteexplorer.search.yahoo.com can output results in tsv format, when opened in excel I get 4 columns. I would like to wget that file, which I can do. I would then like to pull the 2nd column and output it only. I've searched around and found a few bits and pieces but nothing I've... (6 Replies)
Discussion started by: casphar
6 Replies

10. Shell Programming and Scripting

Can we use 'tr' command to print 5th column of output of 'ls -l'

Hi All, I know awk command can do it, but can we use tr command to print 5th column of out put 'ls -l' command???? Regards, Nidhi... (4 Replies)
Discussion started by: Nidhi2177
4 Replies
Login or Register to Ask a Question