1

I have a tab delimited txt file with two columns of data, ex:

PopA 1
PopB 2
PopC 3
PopD 4

I would like to paste a third column for the entire file, with each line being the same, 'EcoRI', thus:

PopA 1 EcoRI
PopB 2 EcoRI
PopC 3 EcoRI
PopD 4 EcoRI

What is a convenient way to do this simple process in Terminal??

Thanks

Mgdesaix
  • 113
  • 6
  • 4
    Possible duplicate of [In Bash, how do I add a string after each line in a file?](https://stackoverflow.com/questions/2869669/in-bash-how-do-i-add-a-string-after-each-line-in-a-file) – Benjamin W. Jan 19 '18 at 14:55
  • 1
    `sed -i.bk 's/$/\tEcoRI/' file.txt` – Samuel Kirschner Jan 19 '18 at 15:12
  • @BenjaminW. thanks, that helped, I was struggling with the different options of `sed` – Mgdesaix Jan 19 '18 at 15:28
  • @SamuelKirschner that did the trick...what does the `-i.bk` specifically refer to. Thanks! – Mgdesaix Jan 19 '18 at 15:29
  • Have a look at `man sed`. The `-i.bk` created a backup file `file.txt.bk`. `-iABC` would create `file.txtABC` as backup. Only `-i` creates no backup. No `-i` at all, does not modify the file, just outputs the result. – Samuel Kirschner Jan 19 '18 at 15:46
  • See this Q&A for in-place specifics with sed in different versions: https://stackoverflow.com/questions/12696125/sed-edit-file-in-place – Benjamin W. Jan 19 '18 at 15:55

1 Answers1

1

Probably this could help:

awk '{print $0 "\tEcoRI"}' file.txt

This will append at the end of each line a tab \t and your text EcoRI

If you would like to save the output you could use:

awk '{print $0 "\tEcoRI"}' file.txt > file2.txt
nbari
  • 25,603
  • 10
  • 76
  • 131
  • thanks, though it appeared to only make a single space instead of a tab between the 2nd and 3rd column...not sure if this would functionally make a difference – Mgdesaix Jan 20 '18 at 16:06
  • The `\t` should add a tab before the text, in any case, after saving the file `file.txt > fiel2.txt` you could use `cat -t file2.txt` the `-t` in cat will help to display not-printing characters so could help to distinguish tabs vs spaces – nbari Jan 21 '18 at 14:35