My string look like this..
foo<..............................
bar</............................
I want to pipe for output as
foo
bar
Delete all characters after a first <
found each line.
My string look like this..
foo<..............................
bar</............................
I want to pipe for output as
foo
bar
Delete all characters after a first <
found each line.
This is basic sed. Using sed is not difficult once you know regular expressions. A basic
sed
command for reading the input and stripping every<
and the following part if it exist, then printing the line (may be modified):sed
uses regular expressions, the relevant manual page text forsed(1)
that applies to the above command:Alternative using
cut
(manual page forcut(1)
), "split the string by<
and take the1
st field.Alternative using
grep
, "match only everything containing characters of the set a to z (case insensitive)" (manual page ofgrep(1)
):(note: I took the liberty to use
[a-z]*
, meaning "zero or more occurrences of a letter", because grep won't return an empty line when using the-o
option)Alternative using awk, using the same idea of
cut
(manual page ofawk(1)
):Sample:
cat textWithFooBar.txt | cut -d '<' -f 1 > output.txt