Jump to content

Annallu Akkallu Unix question ravali


Kumaravaarma

Recommended Posts

2 hours ago, Kumaravaarma said:

@kumar4worldBhayya what does -E and caret do ? 

 

Naa output ila kavali ante malli malli adhe cheputaru. Text_two line ravaddu. 

Let me xplain more in details.

Consider there are three statements and all the 3 are in one file. I want the output which starts with text_* and matching keyword with no coming. Both condition satisfy avvali.

statement#2 key word not coming ledu kadaa anduke statement#2 skip cheyali

 Statement#1

text_one: please_come
 answer: coming and notcoming
 question_to_answer: y

Statement#2
 text_two: plese_donot_come
 answer: nocoming
 question_to_answer: y

Statement#3
 text_three: please_come_aftersome
 answer: coming and nocoming and notcoming
 question_to_answer: y

 

I want the below output

text_one: please_come
 answer: coming and notcoming
 text_three: please_come_aftersome
 answer: coming and nocoming and notcoming

 
thumbnail.jpg?domain=www.electroappsmacs.com
Flash Player for Mac
Stream and View Video, Audio, Multimedia and Rich Internet Applications.
www.electroappsmacs.com
 

 

@Kumaravaarma  grep -E and egrep are same

 

this will work

$ cat file.txt
text_one: please_come
answer: coming and notcoming
question_to_answer: y
text_two: plese_donot_come
answer: nocoming
question_to_answer: y
text_three: please_come_aftersome
answer: coming and nocoming and notcoming
question_to_answer: y


$ while read line1 && read line2 && read line3; do  if  `grep -q "notcoming"  <<< $line2`;then echo $line1 $'\n'$line2; fi; done < file.txt

text_one: please_come
answer: coming and notcoming
text_three: please_come_aftersome
answer: coming and nocoming and notcoming

 

Link to comment
Share on other sites

On 4/24/2020 at 5:45 PM, kumar4world said:

@Kumaravaarma  grep -E and egrep are same

 

this will work


$ cat file.txt
text_one: please_come
answer: coming and notcoming
question_to_answer: y
text_two: plese_donot_come
answer: nocoming
question_to_answer: y
text_three: please_come_aftersome
answer: coming and nocoming and notcoming
question_to_answer: y


$ while read line1 && read line2 && read line3; do  if  `grep -q "notcoming"  <<< $line2`;then echo $line1 $'\n'$line2; fi; done < file.txt

text_one: please_come
answer: coming and notcoming
text_three: please_come_aftersome
answer: coming and nocoming and notcoming

 

Thanks kaka.

btw &&,  <<, $ parameters emm chestadhi.

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...