Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a tab-separated file in Linux that looks like this

~$ head
"1" "FUHGF.jnf.m22-1"
"2" "HDFHFEY.gfs.d2-1"
"3" ""
"4" "SDFSDIB.gfd.rtl2-1"
"5" "FGJFGOB.hgd.k2-5"
"6" "HJLHEH.fc.po2-1"
"7" "GFHFGV.gfn.col2-1"
"8" "KLAA.ghn.xil2-3"
"9" "KJGGFG.hgr.col2-2"

I would like to keep the first part of the name of the second column only. I know I will have to use cut and sed, but I cannot think of the structure of the command. My desired output is

~$ head


I've been trying with awk and gsub but I haven't used Linux for quite some time, help would be appreciated.

Many thanks

share|improve this question
up vote 4 down vote accepted

cut -sf2 -d' '|sed -e 's/\..*/\"/'


  1. cut only the second field in lines with separators (space)
  2. replace the dot and anything that follows with quotation marks.
share|improve this answer
Thanks for the detailed answer :) – Error404 Aug 12 '13 at 17:19

awk '$2 {oFS=FS; FS="."; $0=$2; print $1"\""; FS=oFS}' input

For all lines that have a second field:

  • save the current FS value
  • set FS to .
  • force awk to re-split the second field on the new FS
  • print the first field (and a trailing quotation mark)
  • set FS back to its original value
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.