Quantcast
Channel: Active questions tagged bash+awk - Ask Ubuntu
Viewing all articles
Browse latest Browse all 102

How to use awk to edit a specifc line set by a variable (awk NR, -i inplace and -v var)

$
0
0

If file is:

this is line onethis is line twothis is line three

I want to do something like:

awk -i inplace -v line_number=$line_number 'NR == line_number {print $1}' file 

Lets say line_number=1. Then desired result is:

thisthis is line twothis is line three

But instead, the file is being completely replaced by the edited version of line 1, resulting in:

this

What is the proper way to achieve the desired result?


Viewing all articles
Browse latest Browse all 102

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>