Hi how can I filter the text using this one.
SAMPLE
server[/]vmpool -listall|tail -11
================================================================================
pool number: 112
pool name: Net-Ora-1wk
description: Net-Ora-1wk
max partially full: 0
================================================================================
pool number: 113
pool name: server1-data-3months
description: server1-data-3months
max partially full: 0
================================================================================
server[/]vmpool -listall | grep data
pool name: server1-data-3months
description: server1-data-3months
server[/]
OUTPUT:
I want this to be the output:
pool number: 113
pool name: server1-data-3months
description: server1-data-3months
max partially full: 0
Or
pool number: 113
pool name: server1-data-3months
description: server1-data-3months
max partially full: 0
or
pool number: 113
pool name: server1-data-3months
description: server1-data-3months
My target is to get the pool number also..
Hi
Are you trying to say you want everything other than the "=================================================" line?
Guru.
yes, i want those 4 lines or 3 lines,,
---------- Post updated at 11:10 PM ---------- Previous update was at 11:04 PM ----------
also if you grep a test, how can you display the above and its below???
thanks
Hi
vmpool -listall | grep -v '^===='
Guru.
server[/]vmpool -listall|tail -11
================================================================================
pool number: 112
pool name: Net-Ora-1wk
description: Net-Ora-1wk
max partially full: 0
================================================================================
pool number: 113
pool name: server1-data-3months
description: server1-data-3months
max partially full: 0
================================================================================
server[/]vmpool -listall | grep data
pool name: server1-data-3months
description: server1-data-3months
server[/]
---------- Post updated 06-21-10 at 03:50 AM ---------- Previous update was 06-20-10 at 11:18 PM ----------
Hi, any update please?? I just want that everytime i grep or search for a test, i can get the line above and the line below.
thanks
for example.
#cat file1.txt
yoh yoh
data1
server
base
12345
save
the output should be like this, how??
#grep server file1.txt
data1
server
base
Does your grep know the -C option?
#grep -C1 server file1.txt
data1
server
base
vmpool -listall|grep -Cl
grep: Not a recognized flag: C
Usage: grep [-E|-F] [-c|-l|-q] [-insvxbhwy] [-p[parasep]] -e pattern_list...
[-f pattern_file...] [file...]
Usage: grep [-E|-F] [-c|-l|-q] [-insvxbhwy] [-p[parasep]] [-e pattern_list...]
-f pattern_file... [file...]
Usage: grep [-E|-F] [-c|-l|-q] [-insvxbhwy] [-p[parasep]] pattern_list [file...]
---------- Post updated at 04:16 AM ---------- Previous update was at 04:15 AM ----------
[/COLOR]
vmpool -listall|grep -C1 di
grep: Not a recognized flag: C
grep: Not a recognized flag: 1
Usage: grep [-E|-F] [-c|-l|-q] [-insvxbhwy] [-p[parasep]] -e pattern_list...
[-f pattern_file...] [file...]
Usage: grep [-E|-F] [-c|-l|-q] [-insvxbhwy] [-p[parasep]] [-e pattern_list...]
-f pattern_file... [file...]
Usage: grep [-E|-F] [-c|-l|-q] [-insvxbhwy] [-p[parasep]] pattern_list [file...]
Alright, try these in that case:
Awk:
awk '/server/{if(p) print p; print; if(getline) print}{p=$0}' infile
Sed:
sed -n '/server/{x;1!p;g;$!N;p};h' infile
awk '/server/{if(p) print p; print; if(getline) print}{p=$0}' infile
that line works for me,, thanks a lot...great help..
---------- Post updated at 04:43 AM ---------- Previous update was at 04:43 AM ----------
the sed was not working...thanks..really..
awk ' /server/ { ME=$0;getline; printf("%s\n%s\n%s\n",NI,ME,$0) } { NI=$0 }' file.txt
vmpool -listall| grep -v "===*"
this will work. (-v option displays all the line which doesnt have that specific pattern"
Slight improvement: this also works like grep -C1 for consecutive matches:
awk '{if(/Asterix/){if(p&&!n)print p; print; n=1} else if(n){print;p=n=0} else{p=$0}}' infile
Hi Scrutinizer,
Your last reply is the most accurate however your prevoius answer on awk is suffice...
vmpool -list_all|awk '/CU/{if(p) print p;print; if(getline) print}{p=$0}'
vmpool -listall| awk '{if(/CU/){if(p&&!n)print p; print; n=1} else if(n){print;p=n=0} else{p=$0}}' ---> in this command i was able to get the whole details...thanks...
care to explain them??? the if??? p&&n getline etc??
thanks a lot