Last active
February 19, 2023 02:57
-
-
Save xbalaji/fb8609f3687b0c927e38a7e663e1b5b7 to your computer and use it in GitHub Desktop.
oneliners-sed.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# extract all the links from firefox bookmarks export | |
# the following uses grep to get both http, https url | |
# then uses sed - non-greedy match to extract the link alone | |
grep 'HREF="http' bookmarks.html | sed -e 's,.*HREF="\([^"]*\)".*,\1,g' | sort | less | |
# replace a bunch of lines in the middle of a file with ... blah ... | |
cat 40lines.txt | sed -e '6,34d; 35{i ... blah ...' -e 'd}' | |
cat 40lines.txt | sed -e '6,33d; 34,36s,.*,,;35s// ... blah .../' | |
# replace with contents from a file | |
echo -e "line 1\nline 2\nline 3" > replace.txt | |
cat 40lines.txt | sed -e '6,35{R replace.txt' -e 'd}' | |
# see here - https://unix.stackexchange.com/questions/405715/using-sed-to-replace-first-n-lines-in-a-file-with-the-first-n-lines-from-another | |
# 40 lines are generated using | |
curl -sk http://metaphorpsum.com/sentences/40 | gawk 'BEGIN {RS="."} { gsub(/^ /,"", $0); printf "%2d %s\n", NR, $0}' > 40lines.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment