Score:0

Infinite loop being generated using paste to stick together columns of tab delineated data

cl flag

Working with files containing many long columns of data, I'm trying to summarise all the data of one category as a series of tab delineated columns using paste. All of the files, of which there are 30, are named "output1234", and I want to cut out column six, and paste all the column sixes together in one file. I have a variable, $SAMPLE_ID which contains the "1234" part of each filename. Here is my BASH code:

#!/bin/bash

touch category6_table
for x in $SAMPLE_ID; do
   paste "$(cut -f6 output${x})" expression_table > expression_table

done

If I run this, it seems to get stuck in a loop and generate an infinitely long list of numbers.

EDIT: found a solution here https://unix.stackexchange.com/questions/141571/how-to-use-paste-command-for-many-files-whose-names-are-not-numbers-paste-colu

hr flag
Because redirections are set up before commands are run, the `expression_table` file gets truncated (i.e. emptied) at each iteration - see this similar Q&A [add column and save file](https://askubuntu.com/questions/837968/add-column-and-save-file)
hr flag
... I'd suggest trying something like `cut -f6 "output${x}" | paste expression_table - | sponge expression_table` where the `sponge` command is provided by the moreutils package
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.