Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

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

Given: there are 40 columns in a record. I want to replace the 35th column so that the 35th column will be replaced with the content of the 35th column and a "$" symbol. What came to mind is something like:

awk '{print $1" "$2" "...$35"$ "$36...$40}'

It works but because it is infeasible when the number of column is as large as 10k. I need a better way to do this.

share|improve this question
up vote 11 down vote accepted

You can do like this:

awk '$35=$35"$"'
share|improve this answer

There are probably more efficient ways to do this. With that caveat:

awk '{$35 = $35"$"; print}' infile > outfile
share|improve this answer

If the field delimiter is <space>:

sed 's/  */$&/35'
share|improve this answer
If the field delimiter is unknown: sed 's/./$&/35' – Underverse Jul 6 '15 at 1:38
@Underverse - I don't think that's the same thing. That should prefix the 35th char on an input line w/ the char $ - delimited or not. The thing above should affix the 35th occurrence of any number of delimiter chars - in other words, the 35th field - with the char $ - no matter how chars are in each field. – mikeserv Jul 6 '15 at 1:43
Ah, "40 columns in a record". I read 'the 35th column' as literally 'the 35th character column of the text file'. – Underverse Jul 6 '15 at 1:57

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.