17 private links
jq is like sed
for JSON data - you can use it to slice and filter and map and transform structured data with the same ease that sed
, awk
, grep
and friends let you play with text.
jq is written in portable C, and it has zero runtime dependencies. You can download a single binary, scp it to a far away machine of the same type, and expect it to work.
jq can mangle the data format that you have into the one that you want with very little effort, and the program to do so is often shorter and simpler than you’d expect.
sed
is stream editor, but can edit files directly too, with the following:
sed -i -e 's/foo/bar/g' filename
s
is used to replace the found expression "foo" with "bar"
g
stands for "global", meaning to do this for the whole line. If you leave off the g
and "foo" appears twice on the same line, only the first "foo" is changed to "bar".
-i
option is used to edit in place on filename.
-e
option indicates a command to run.
Un aide mémoire
It's an interesting dilemma. There are two obstacles to doing this in sed. One is that sed operates line by line and never sees the newline endings. Second, sed's regular expressions don't provide a way to exactly match a newline character.
If you really want to do this, don't use sed; use tr.
cat file | tr '\n' ','
To remove the line and print the output to standard out:
sed '/pattern to match/d' ./infile
To directly modify the file (with GNU sed):
sed -i '/pattern to match/d' ./infile