Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

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

3 Answers 3

up vote 8 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 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 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 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.