I have file as
0::question#1::
Love
giberrish fdfd
1::anything#2:
Is
repeat
22::anything#3::
LieI want to extract
Love
giberish
****
Is
repeat
****
Liecat file.txt | sed 's/::\n([^\n]*)/\1/g'
I'm getting file as
0::question#1::
Love
1::anything#2:
Is
22::anything#3::
LieOn testing regex is matching here
UPDATE I missed to tell, that file extract is for for multi-line not single line and also i want a deliminator as well. I apologize for trouble
cat org_op.2019.04.06-09.43.59 | sed 's/^.*::.*//g;/^$/d'
I get output as
Love
giberrish fdfd
Is
repeat 2 4 4
LieSo I added some deliminator in order to split one record from another
cat org_op.2019.04.06-09.43.59 | sed 's/^.*::.*/***/g;/^$/d'
and got
***
Love
giberrish fdfd ***
Is
repeat 2 4 4 ***
LieTo remove top-line i used
cat org_op.2019.04.06-09.43.59 | sed 's/^.*::.*/ ***/g;/^$/d' | tail -n +2
new output is
Love giberrish fdfd *** Is repeat 2 4 4 *** LieI want to capture each record using awk i did
cat org_op.2019.04.06-09.43.59 | sed 's/^.*::.*/ ***/g;/^$/d' | tail -n +2 | awk 'BEGIN{ RS = "" ; FS = "***" }{print $1}'
I get output
Love
giberrish fdfdI'm unable to remove last empty line which is same across all fields i tried using pipe to sed with /^$/d didn't work
UPDATE 2got it working by
``sed 's/^.::.//g;/^$/d' | tail -n +2 | awk 'BEGIN{ RS = "" ; FS = "" }{print $1}' | sed -e '/^$/d'`
32 Answers
sed '/^[0-9]/d; /^$/d' file.txt
Love
Is
Lie/^[0-9]/d: remove lines starting with a number/^$/d: remove empty lines
Use the method of matching lines then remnove those matching lines and then remove the spaces...
sed -e '/^.*::.*/d' -e '/^$/d' data.txtResult:
Love
Is
LieOr a shorter version:
sed -E '/^(.*::.*)?$/d'Info:
'/^.*::.*/d': Match lines with::and delete them'/^$/d': Remove all blank lines