Score:0

Remove next line after specific character

ci flag

I would like to remove the word that comes after a specific character in a text file. For instance:

.
I
am
Anders
<<
Thank
you

to be

.
am
Anders
<<
you

or

am
Anders
you

How is that possible? I can remove the dots by saying:

sed 's/\.*//' *.txt

Kind regards Anders

elmclose avatar
cn flag
Does your file have just one word per line?
Andrej Podzimek avatar
cn flag
`awk 'BEGIN {next_out = 1} {out = next_out; next_out = 1} /^[.]/ {next_out = 0} out' < some_text_file` (And then it’s a matter of adding all relevant characters into the regexp or otherwise adjusting it to match everything you want.)
Score:1
hr flag

Given

$ cat file
.
I
am
Anders
<<
Thank
you

then

$ sed '/[.<]/{n;d;}' file
.
am
Anders
<<
you

and

$ sed '/[.<]/{N;d;}' file
am
Anders
you
Anders Begtorp avatar
ci flag
Thank you so much! It works :-)
Score:0
cn flag

Try this:

awk '!flag{print}{flag=($0=="Anders")? 1:0}' infile
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.