0

When dealing with large files it is often useful to use commands like head, tail, to look at subsets of a file.

I'm wondering if there is a utility for editing subsets files? I just encountered a situation where I wanted to edit the first line of a file, and ended up loading the whole thing into vim.

4

1 回答 1

2

You can try sed(stream editor), to replace foo with bar

# edit 1st line
sed -i '1s/foo/bar/g' file.txt

# edit line 10~20
sed -i '10,20s/foo/bar/g' file.txt

There's many commands in sed, read the doc.

于 2013-09-26T03:42:26.920 回答