Replace all whitespace with a line break/paragraph mark to make a word list

For reasonably modern versions of sed, edit the standard input to yield the standard output with $ echo ‘τέχνη βιβλίο γη κήπος’ | sed -E -e ‘s/[[:blank:]]+/\n/g’ τέχνη βιβλίο γη κήπος If your vocabulary words are in files named lesson1 and lesson2, redirect sed’s standard output to the file all-vocab with sed -E -e ‘s/[[:blank:]]+/\n/g’ … Read more

Can I use sed to manipulate a variable in bash?

Try this: website=$(sed ‘s”https://stackoverflow.com/”\\/|g’ <<< $website) Bash actually supports this sort of replacement natively: ${parameter/pattern/string} — replace the first match of pattern with string. ${parameter//pattern/string} — replace all matches of pattern with string. Therefore you can do: website=${website////\\/} Explanation: website=${website // / / \\/} ^ ^ ^ ^ | | | | | | | … Read more

How to use sed to extract substring

grep was born to extract things: grep -Po ‘name=”\K[^”]*’ test with your data: kent$ echo ‘<parameter name=”PortMappingEnabled” access=”readWrite” type=”xsd:boolean”></parameter> <parameter name=”PortMappingLeaseDuration” access=”readWrite” activeNotify=”canDeny” type=”xsd:unsignedInt”></parameter> <parameter name=”RemoteHost” access=”readWrite”></parameter> <parameter name=”ExternalPort” access=”readWrite” type=”xsd:unsignedInt”></parameter> <parameter name=”ExternalPortEndRange” access=”readWrite” type=”xsd:unsignedInt”></parameter> <parameter name=”InternalPort” access=”readWrite” type=”xsd:unsignedInt”></parameter> <parameter name=”PortMappingProtocol” access=”readWrite”></parameter> <parameter name=”InternalClient” access=”readWrite”></parameter> <parameter name=”PortMappingDescription” access=”readWrite”></parameter> ‘|grep -Po ‘name=”\K[^”]*’ PortMappingEnabled PortMappingLeaseDuration RemoteHost ExternalPort … Read more

find difference between two text files with one item per line [duplicate]

grep -Fxvf file1 file2 What the flags mean: -F, –fixed-strings Interpret PATTERN as a list of fixed strings, separated by newlines, any of which is to be matched. -x, –line-regexp Select only those matches that exactly match the whole line. -v, –invert-match Invert the sense of matching, to select non-matching lines. -f FILE, –file=FILE Obtain … Read more

Have sed ignore non-matching lines

If you don’t want to print lines that don’t match, you can use the combination of -n option which tells sed not to print p flag which tells sed to print what is matched This gives: sed -n ‘s/…/…/p’ Additionally, you can use a preceding matching pattern /match only these lines/ to only apply the … Read more

How to change date format in sed?

e switch in sed substitute applies sh -c to unmatched text as well as evident from this command: echo ‘a 1449158360’ | sed -r ‘s#([0-9]{10})#date -d@\1 “+%Y”;#e’ sh: a: command not found So even though we are matching only 1449158360 but sh -c is being run on a 1449158360. Due to absence of non-greedy and … Read more