Pages

Showing posts with label SED. Show all posts
Showing posts with label SED. Show all posts

Monday, July 1, 2024

SED

 1) how to ignore sed operation in last line alone


# sed -e "$ ! s/a/b/"


2) SED Remove last character from line 


# sed 's/.$//'

Monday, February 18, 2019

SED Options

Example HTML page
We know sed command is used for file processing.

To Match Digit

sed -r 's/([^0-9]*([0-9]*)){2}.*/\2/' file

This extracts the second number:


sed -r 's/([^0-9]*([0-9]*)){1}.*/\2/' file

sed 's/[[:digit:]]\+\.//g'

$ echo "This is an example: 65 apples" | sed -r  's/^[^0-9]*([0-9]+).*/\1/'

65

59

Two problems:

sed does not support \d. Use [0-9] or [[:digit:]].


+ must be backslashed to get the special meaning: \+.

sed -r 's/.*_([0-9]*)\..*/\1/g'