Pasting first row behind every column in Linux

awk filter rows by column value
awk '(print first column)
awk print first n columns
cut first column from a file in unix
unix command to extract specific column from a file
awk print column
linux column command
linux cut

I have a tab-delimited file as such (but with way more columns)

1       2          3        4        5       6 
gene1   gene39   gene339   gene2     gene1   gene2
gene3   gene9    gene23    gene5     gene11  gene3
gene23  gene9    gene8     gene1     gene7   gene8

I want to take each column 1, and paste it alongside that column. It would look something like this

gene1  1   gene39  2   gene339  3   gene2  4   gene1   5  gene2  6
gene3  1   gene9   2   gene23   3   gene5  4   gene11  5  gene3  6
gene23 1   gene9   2   gene8    3   gene1  4   gene7   5  gene8  6

Any help would be great!

$ awk 'BEGIN{FS=OFS="\t"} NR>1{ for (i=1; i<=NF; i++) printf "%s%s%s%s", $i, OFS, i, (i<NF ? OFS : ORS) }' file
gene1   1       gene39  2       gene339 3       gene2   4       gene1   5       gene2   6
gene3   1       gene9   2       gene23  3       gene5   4       gene11  5       gene3   6
gene23  1       gene9   2       gene8   3       gene1   4       gene7   5       gene8   6

Pasting first row behind every column in Linux, Pasting first row behind every column in Linux. sed add column to file how to add a column in a file using unix adding a column to a text file awk sed command Merge a file by pasting the data into 2 columns : $ paste - - < file1 Linux Unix Solaris HPUX AIX The '-' reads a line from the standard input. Two '-' reads 2 lines and pastes them side by side.

Assuming the columns are numbered sequentially, would this work?

NR > 1 {
  for (i=1; i<=NF; i++) {
    printf "%s %d ", $i, i
  }
  print
}

Beginning Ubuntu Linux: Natty Narwhal Edition, You can reuse formulas simply by cutting and pasting them. The filter function in Calc lets you selectively hide rows of data. to filter the rows, or select Autofilter to choose from a drop-down list that appears in the cell at the top of the column. A wizard dialog box appears, and a rough draft of the chart appears behind. Paste column from one file as column of I need to cut the column 4 values from File1 and paste them as column4 values of File2, but only for the (first) same number of lines as File1 . All rows in File1 are contained in File2 in the exact same order, so the cut paste should work.

awk 'NR>1{for(i=1;i<NF;i++){ printf "%s\t%s\t", $i,i};printf "%s\t%s\n", $NF,NF}' steveman
gene1   1       gene39  2       gene339 3       gene2   4       gene1   5       gene2   6
gene3   1       gene9   2       gene23  3       gene5   4       gene11  5       gene3   6
gene23  1       gene9   2       gene8   3       gene1   4       gene7   5       gene8   6

Six glorious commands worth getting to know, Getting started; cut; grep; paste; sed; awk; tr Let's look at just the first row using the head command and only pulling out 1 line so we can All we need to do is tell cut which fields we want (columns), and which file we want it to cut them from. Pasting a column into a text file . I have two text files: One is a single column of numbers and the other is a space delimited text file with multiple columns. I want to paste the single column of numbers into the second column of the latter text file. H

If you are considering Perl,

$ cat steveman.txt
1       2          3        4        5       6
gene1   gene39   gene339   gene2     gene1   gene2
gene3   gene9    gene23    gene5     gene11  gene3
gene23  gene9    gene8     gene1     gene7   gene8
$ perl -F"/\s+/" -lane ' @FH=@F if $.==1; if($.>1) { for($i=0;$i<@F;$i++) { printf("%s\t%s\t",$F[$i],$FH[$i]) } print "" } ' steveman.txt
gene1   1       gene39  2       gene339 3       gene2   4       gene1   5       gene2   6
gene3   1       gene9   2       gene23  3       gene5   4       gene11  5       gene3   6
gene23  1       gene9   2       gene8   3       gene1   4       gene7   5       gene8   6
$

Moving data between R and Excel via the clipboard, You can use the scan function to copy a column of numbers from Excel to R. To copy a row from Excel, first transpose the row in Excel, then copy the result as a sep="\t") will copy a table x to the clipboard in such a way that it can be pasted To leave the row names behind, add the argument row.names=FALSE to the  flack 2.0.6: menu-driven BASH script to easily tag FLAC files knock-once 1.2: BASH script to easily create/send one-time sequences for knockd ()

10 incredibly useful Excel keyboard tips, Microsoft Excel has a host of keyboard shortcuts that you can use to speed If you want to check your work, you can always click on a cell to see the formula behind the cell's value; How to easily flip a column of data to a row in Excel first cell of the column, hold Shift and double-click the lower border of  Copy all of these cells and paste them in the cells where you want to paste them. Next, highlight all of the cells in both columns. Hold down the shift key and highlight all cells in one

Command Line Tricks For Data Scientists, It is, after all, why these tools exist in the first place. To understand some of the magic behind UTF-8, check out this excellent video. Sorting a CSV file by the second column alphabetically sort -t"," -k2,2 filename.csv # Numerically sort -t"," -​k2n,2 Paste is a niche command with an interesting function. I found this post, modified it to fit my needs. Will paste transpose. Sub Transpose_PasteModified() Dim source As Worksheet Dim destination As Worksheet Dim emptyColumn As Long Set source = Sheets("Sheet1") Set destination = Sheets("Sheet2") 'Data Source source.Range("A3:C3").Copy 'Gets Empty Column emptyColumn = destination.Cells(3, destination.Columns.Count).End(xlToLeft).Column 'In order to

How to move columns/rows in Calc?, It is necessary to drag not by column/row index but by one of cells. else it creates a new column with the data and leaves behind an empty column. That means to drag cells in Libreoffice under Linux, you have You can select either a rectangle, or a group of entire rows or columns using the top or left  The first sheet is easy because I can paste the entire sheet however after that it becomes tricky as I only need from A5-H### as I no longer need the header. I then need to paste this information at the bottom of the previous paste. I am getting a Range of Object "_Global" failed for the 'Range(lastRow).Select'. The issue is when I look at it in the debugger it is coming up with the correct

Comments
  • And make sure the title says what you mean. You say in front of every column, but your sample output has it behind every column.
  • I didn't bother trying to get the columns nicely aligned as I presumed it wouldn't make any differences when text-processing this. I can see that you and @tink have done that so it must be important. Why though?
  • The OP said he had tab-delimited input so I just gave him tab-delimited output. I assume he has his reasons - maybe he has some other tool he uses on it that expects tab-delimited fields or maybe he just thinks it looks pretty or MAYBE his real data can have blank chars within fields, idk.
  • @customcommander so to be clear, I didn't care about the alignment (if I did I'd just pipe the output to column), but I did care about the separator and that just coincidentally with the given sample input produces visually aligned output.
  • Yeah I can see that in your BEGIN clause; clever :-) +1
  • The only real problem with that is it'll add a blank to the end of every line.