grep - search after line containing "unavailable"


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep - search after line containing "unavailable"
# 1  
Old 10-19-2010
Data grep - search after line containing "unavailable"

Hi everybody;
I have a file status.txt:

Code:
Following 163 ports are up:
-----------------------------------------------------
MOD  PORT     PORTNAMES      ABCDEFG1 ABCDEFG2 STA   TYPE
1  Prt122   port323-1/2/3   11111       11111      1111   A
1  Prt126   port328-1/2/3   11111       11111      1111   A
1  Prt129   port331-1/2/3   111111     111111     1111   A
...
...
1       Prt129   port331-1/2/3   111111     111111     1111   A

-----------------------------------------------------
Following 3 ports are totally or partially unavailable:
-----------------------------------------------------
MOD  PORT     PORTNAMES      ABCDEFG1 ABCDEFG2 STA   TYPE
1       Prt122   port323-1/2/3   LLLLL       000000     1111    A
1       Prt126   port328-1/2/3   L00000    100011      1111   A
1       Prt129   port331-1/2/3   100011    111111      1111   A

i want to print unavailable ports to a file una.txt. I want to say:

search for lines after word "unavailable" and write those 3 lines to file una.txt. All delimiters are space. SmilieSmilieSmilieSmilie

thanks people..
# 2  
Old 10-19-2010
Code:
awk '/unavailable/{p=1}p' status.txt > una.txt

This User Gave Thanks to bartus11 For This Post:
# 3  
Old 10-19-2010
@bartus11

Could you pls tell how this command works..especially {p=1}p
# 4  
Old 10-19-2010
thanks but error:

Code:
awk: syntax error near line 1
awk: bailing out near line 1

do you have another solution??
# 5  
Old 10-19-2010
Quote:
Originally Posted by gc_sw
thanks but error:

Code:
awk: syntax error near line 1
awk: bailing out near line 1

do you have another solution??
Try:
Code:
nawk '/unavailable/{p=1}p' status.txt > una.txt

BTW.. next time warn us that you are using Solaris :P
This User Gave Thanks to bartus11 For This Post:
# 6  
Old 10-19-2010
If given is the exact content of the file status.txt.. then

Code:
sed '/unavailable/,/ $/!d' status.txt > una.txt

This User Gave Thanks to michaelrozar17 For This Post:
# 7  
Old 10-19-2010
Quote:
Originally Posted by bartus11
Try:
Code:
nawk '/unavailable/{p=1}p' status.txt > una.txt

BTW.. next time warn us that you are using Solaris :P
thank you very much. it works SmilieSmilieSmilie

---------- Post updated at 11:34 ---------- Previous update was at 11:33 ----------

Quote:
Originally Posted by michaelrozar17
If given is the exact content of the file status.txt.. then

Code:
sed '/unavailable/,/ $/!d' status.txt > una.txt

thanks but it outputs only first line. not the others. "nawk" solution is OK Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Failure: if grep "$Var" "$line" inside while read line loop

Hi everybody, I am new at Unix/Bourne shell scripting and with my youngest experiences, I will not become very old with it :o My code: #!/bin/sh set -e set -u export IFS= optl="Optl" LOCSTORCLI="/opt/lsi/storcli/storcli" ($LOCSTORCLI /c0 /vall show | grep RAID | cut -d " "... (5 Replies)
Discussion started by: Subsonic66
5 Replies

2. Shell Programming and Scripting

Find lines with "A" then change "E" to "X" same line

I have a bunch of random character lines like ABCEDFG. I want to find all lines with "A" and then change any "E" to "X" in the same line. ALL lines with "A" will have an "X" somewhere in it. I have tried sed awk and vi editor. I get close, not quite there. I know someone has already solved this... (10 Replies)
Discussion started by: nightwatchrenba
10 Replies

3. Shell Programming and Scripting

grep with "[" and "]" and "dot" within the search string

Hello. Following recommendations for one of my threads, this is working perfectly : #!/bin/bash CNT=$( grep -c -e "some text 1" -e "some text 2" -e "some text 3" "/tmp/log_file.txt" ) Now I need a grep success for some thing like : #!/bin/bash CNT=$( grep -c -e "some text_1... (4 Replies)
Discussion started by: jcdole
4 Replies

4. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

5. Shell Programming and Scripting

ps -ef | grep "string1" "string2" " "string3"

Hi all, can any one suggest me the script to grep multiple strings from ps -ef pls correct the below script . its not working/ i want to print OK if all the below process are running in my solaris system. else i want to print NOT OK. bash-3.00$ ps -ef | grep blu lscpusr 48 42 ... (11 Replies)
Discussion started by: steve2216
11 Replies

6. UNIX for Dummies Questions & Answers

How to use the "grep/egrep" command to search files.

Hi Team, I am new to this forum and also trying to learn Unix. I will highly appriciate your help if you can help me to get the right command . {{{ I use the command " today | egrep '(10:| 11: )' | grep ERROR " to grep all the files that has been error betweeen 10 to 11... (6 Replies)
Discussion started by: rkhanal
6 Replies

7. Shell Programming and Scripting

ls -laR | grep "^-" | awk '{print $9}'| grep "$.txt"

Hi, I don't know hot to make this command work: ls -laR | grep "^-" | awk '{print $9}'| grep "$.txt" It should return the list of file .txt It's important to search .txt at the end of the line, becouse some file name have "txt" in their name but have other extensions (13 Replies)
Discussion started by: DNAx86
13 Replies

8. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

9. Solaris

sendto failing "resource temporarily unavailable"

Well, I am not even sure if its failing, cause at the other end I have a select call and it wakes up and reads the data I sent fine. Ok here is the issue, I have a UDP socket(non blocking) through which I push some data to another port. At the other end I have select loop, waiting for this data.... (6 Replies)
Discussion started by: Naanu
6 Replies

10. UNIX for Dummies Questions & Answers

grep/cat/more -- search in a txt file and display content from a specific "keyword"

Hi, I have a .txt file Sample: ===================== NEXT HOST ===================== AEADBAS001 ip access-list extended BLA_Incoming_Filter ip access-list extended BLA_Outgoing_Filter access-list 1 permit xxxxxxxxxxxxxx access-list 2 permit xxxxxxxxxxxxxx =====================... (4 Replies)
Discussion started by: I-1
4 Replies
Login or Register to Ask a Question