Need to grep this Data in proper format:- Please Guide

Hi Guys,
I need to grep below data in this format
backup_id
creation
expiration
policy
sched_label

backup_id = picoserver38_1212077050, version = 2
creation = 05/29/2008 18:04:10 (1212077050)
expiration = 06/29/2008 18:04:10 (1214755450)
retention_level = 3, fragment = 2, file_num = 1
block_size = 262144, status = 0x0
media_id = ADC020, size = 0, data_start = 2
client_type = 13, copy_num = 1
sched_type = 0, flags = 0x0
policy = picoserver38_san
sched_label = picoserver38_full_daily
opt_extra = 0, mpx_headers = 1, res1 = 0
backup_id = picoserver38_1212076929, version = 2
creation = 05/29/2008 18:02:09 (1212076929)
expiration = 06/29/2008 18:02:09 (1214755329)
retention_level = 3, fragment = 3, file_num = 2
block_size = 262144, status = 0x0
media_id = ADC020, size = 0, data_start = 108410
client_type = 13, copy_num = 1
sched_type = 0, flags = 0x0
policy = picoserver38_san
sched_label = picoserver38_full_daily
opt_extra = 0, mpx_headers = 2, res1 = 0

I could grep only this, media_id did not come here.

-bash-3.00$  sudo /usr/openv/netbackup/bin/admincmd/bpmedialist -mcontents -m ADC020 -L | grep creation | grep -v 'media_id'
creation = 05/29/2008 18:02:09 (1212076929)
creation = 05/29/2008 18:04:09 (1212077049)
creation = 05/29/2008 18:04:10 (1212077050)
creation = 05/29/2008 18:02:09 (1212076929)
creation = 05/29/2008 18:04:09 (1212077049)

Please Advise.
Thanks.

 grep -E "^backup_id|^creation|^expiration|^policy|^sched_label" filename
1 Like

But I need to run command which shows output and i want to grep that output in one go.

This is command i need to run
sudo /usr/openv/netbackup/bin/admincmd/bpmedialist -mcontents -m ADC020 -L

It is showing below error in Solaris 10

-bash-3.00$ sudo /usr/openv/netbackup/bin/admincmd/bpmedialist -mcontents -m ADC020 -L | grep -E "^backup_id|^creation|^expiration|^policy|^sched_label"
grep: illegal option -- E
Usage: grep -hblcnsviw pattern file . . .
cat file | grep -E "backup_id|creation|expiration|policy|sched_label" | awk '{print "creation",$2,$3,$4,$5}' | grep -v 38_
1 Like

Thanks showing below error in solaris 10

-bash-3.00$ cat ADC020  | grep -E "backup_id|creation|expiration|policy|sched_label"
grep: illegal option -- E
Usage: grep -hblcnsviw pattern file . . .
-bash-3.00$
sudo /usr/openv/netbackup/bin/admincmd/bpmedialist -mcontents -m ADC020 -L | grep "^backup_id\|^creation\|^expiration\|^policy\|^sched_label"

OR

 sudo /usr/openv/netbackup/bin/admincmd/bpmedialist -mcontents -m ADC020 -L | /usr/sfw/bin/ggrep -E "^backup_id|^creation|^expiration|^policy|^sched_label" 
1 Like

Let me check, .....checking now.........

---------- Post updated at 11:47 AM ---------- Previous update was at 11:43 AM ----------

The first one did not produce any output, checking 2nd one.

---------- Post updated at 11:52 AM ---------- Previous update was at 11:47 AM ----------

Hey.It produce the output in follwoing way,

-bash-3.00$ sudo /usr/openv/netbackup/bin/admincmd/bpmedialist -mcontents -m ADC020 -L | /usr/sfw/bin/ggrep -E "^backup_id|^creation|^expiration|^policy|^sched_label"
expiration = N.A (0)
backup_id = picoserver38_1212076929, version = 2
creation = 05/29/2008 18:02:09 (1212076929)
expiration = 06/29/2008 18:02:09 (1214755329)
policy = picoserver38_san
sched_label = picoserver38_full_daily
backup_id = picoserver38_1212077049, version = 2
creation = 05/29/2008 18:04:09 (1212077049)
expiration = 06/29/2008 18:04:09 (1214755449)
policy = picoserver38_san
sched_label = picoserver38_full_daily
backup_id = picoserver38_1212077050, version = 2
creation = 05/29/2008 18:04:10 (1212077050)
expiration = 06/29/2008 18:04:10 (1214755450)
policy = picoserver38_san
sched_label = picoserver38_full_daily
backup_id = picoserver38_1212076929, version = 2
creation = 05/29/2008 18:02:09 (1212076929)
expiration = 06/29/2008 18:02:09 (1214755329)
policy = picoserver38_san
sched_label = picoserver38_full_daily
backup_id = picoserver38_1212077049, version = 2
creation = 05/29/2008 18:04:09 (1212077049)
expiration = 06/29/2008 18:04:09 (1214755449)
policy = picoserver38_san
sched_label = picoserver38_full_daily
-bash-3.00$

Can I produce it in column format or so with awk etc?

Could you please provide desire output ?

1 Like

I used this one

-bash-3.00$ sudo /usr/openv/netbackup/bin/admincmd/bpmedialist -mcontents -m ADC020 -L | /usr/sfw/bin/ggrep -E "^backup_id|^creation|^expiration|^policy|^sched_label" | awk '{print "creation",$2,$3,$4,$5}'
Password:
creation = N.A (0)
creation = picoserver38_1212076929, version =
creation = 05/29/2008 18:02:09 (1212076929)
creation = 06/29/2008 18:02:09 (1214755329)
creation = picoserver38_san
creation = picoserver38_full_daily
creation = picoserver38_1212077049, version =
creation = 05/29/2008 18:04:09 (1212077049)
creation = 06/29/2008 18:04:09 (1214755449)
creation = picoserver38_san
creation = picoserver38_full_daily
creation = picoserver38_1212077050, version =
creation = 05/29/2008 18:04:10 (1212077050)
creation = 06/29/2008 18:04:10 (1214755450)
creation = picoserver38_san
creation = picoserver38_full_daily
creation = picoserver38_1212076929, version =
creation = 05/29/2008 18:02:09 (1212076929)
creation = 06/29/2008 18:02:09 (1214755329)
creation = picoserver38_san
creation = picoserver38_full_daily
creation = picoserver38_1212077049, version =
creation = 05/29/2008 18:04:09 (1212077049)
creation = 06/29/2008 18:04:09 (1214755449)
creation = picoserver38_san
creation = picoserver38_full_daily
-bash-3.00$

Can I have something like this in column

Media_id |backup_id | Policy | sched_label | creation | expiration |

I mean from one paragraph into one row, below are the two paragraphs.

backup_id = picoserver38_1212076929, version = 2
creation = 05/29/2008 18:02:09 (1212076929)
expiration = 06/29/2008 18:02:09 (1214755329)
retention_level = 3, fragment = 3, file_num = 2
block_size = 262144, status = 0x0
media_id = ADC020, size = 0, data_start = 108410
client_type = 13, copy_num = 1
sched_type = 0, flags = 0x0
policy = picoserver38_san
sched_label = picoserver38_full_daily
opt_extra = 0, mpx_headers = 2, res1 = 0
 
backup_id = picoserver38_1212077049, version = 2
creation = 05/29/2008 18:04:09 (1212077049)
expiration = 06/29/2008 18:04:09 (1214755449)
retention_level = 3, fragment = 3, file_num = 2
block_size = 262144, status = 0x0
media_id = ADC020, size = 0, data_start = 108410
client_type = 13, copy_num = 1
sched_type = 0, flags = 0x0
policy = picoserver38_san
sched_label = picoserver38_full_daily
opt_extra = 0, mpx_headers = 1, res1 = 0

Thanks for you help till now.

Please advise.

---------- Post updated at 12:13 PM ---------- Previous update was at 12:01 PM ----------

I need below info only , its ok if I dont get media_id as I am running command with media_id only.

-bash-3.00$ sudo /usr/openv/netbackup/bin/admincmd/bpmedialist -mcontents -m ADC020 -L | /usr/sfw/bin/ggrep -E "^media_id|^backup_id|^creation|^expiration|^policy|^sched_label"
Password:
media_id = ADC020, partner_id = *NULL*, version = 1
expiration = N.A (0)
backup_id = picoserver38_1212076929, version = 2
creation = 05/29/2008 18:02:09 (1212076929)
expiration = 06/29/2008 18:02:09 (1214755329)
media_id = ADC020, size = 0, data_start = 2
policy = picoserver38_san
sched_label = picoserver38_full_daily
backup_id = picoserver38_1212077049, version = 2
creation = 05/29/2008 18:04:09 (1212077049)
expiration = 06/29/2008 18:04:09 (1214755449)
media_id = ADC020, size = 0, data_start = 2
policy = picoserver38_san
sched_label = picoserver38_full_daily
backup_id = picoserver38_1212077050, version = 2
creation = 05/29/2008 18:04:10 (1212077050)
expiration = 06/29/2008 18:04:10 (1214755450)
media_id = ADC020, size = 0, data_start = 2
policy = picoserver38_san
sched_label = picoserver38_full_daily
backup_id = picoserver38_1212076929, version = 2
creation = 05/29/2008 18:02:09 (1212076929)
expiration = 06/29/2008 18:02:09 (1214755329)
media_id = ADC020, size = 0, data_start = 108410
policy = picoserver38_san
sched_label = picoserver38_full_daily
backup_id = picoserver38_1212077049, version = 2
creation = 05/29/2008 18:04:09 (1212077049)
expiration = 06/29/2008 18:04:09 (1214755449)
media_id = ADC020, size = 0, data_start = 108410
policy = picoserver38_san
sched_label = picoserver38_full_daily
-bash-3.00$

Above bold info is what I need.

Thanks.

---------- Post updated at 02:17 PM ---------- Previous update was at 12:13 PM ----------

Hey please answer me,

How can I use below command with awk for expiration and policy and sched_label

sudo /usr/openv/netbackup/bin/admincmd/bpmedialist -mcontents -m ADC020 -L | /usr/sfw/bin/ggrep -E "^backup_id|^creation|^expiration|^policy|^sched_label" | awk '{print "creation",$2,$3,$4,$5}'

Please guide

I mean do I have use something like this :-

sudo /usr/openv/netbackup/bin/admincmd/bpmedialist -mcontents -m ADC020 -L | /usr/sfw/bin/ggrep -E "^backup_id|^creation|^expiration|^policy|^sched_label" | awk '{print "creation","policy",$2,$3,$4,$5}'
sudo /usr/openv/netbackup/bin/admincmd/bpmedialist -mcontents -m ADC020 -L | awk -F"=" '/^backup_id/{$1="";backup_id[++i]=$0}
/^creation/{$1="";creation=$0}
/^expiration/{$1="";expiration=$0}
/^media_id/{$1="";media_id=$0}
/^policy/{$1="";policy=$0}
/^sched_label/{$1="";sched_label=$0}
END { print "Media_id |backup_id | Policy | sched_label | creation | expiration";for(j=1;j<=i;j++) {
print media_id[j]"|"backup_id[j]"|"policy[j]"|"sched_label[j]"|"creation[j]"|"expiration[j]
}}' 
1 Like

Wow! Looks fine.

You mean to say I need to create a script for this?
But I need to yun this for almost 100 Tape numbers ADC001 too ADC100.
My machine is production machine.:frowning: The backup Server:rolleyes:

However I have one tiny query, i searched google a lot but did not get answer,
how to grep word only once without repeating

-bash-3.00$ cat /zFINAL142TAPES/ADC094.txt  | grep policy  intel_class_i
policy = ams_linux_prod1
policy = ams_linux_prod1
policy = ams_linux_prod1
policy = ams_linux_prod1
policy = ams_linux_prod1
policy = ams_linux_prod1
policy = ams_linux_prod1
policy = ams_linux_prod1
policy = ams_linux_prod1
policy = ams_linux_prod1
policy = ams_linux_prod1
policy = ams_linux_prod1
policy = ams_linux_prod1
policy = ams_linux_prod1
policy = ams_linux_prod1
policy = ams_linux_prod1
policy = ams_linux_prod1
policy = ams_linux_prod1
policy = ams_linux_prod1
policy = ams_linux_prod1
policy = ams_linux_prod1
policy = ams_linux_prod1
policy = ams_linux_prod1
policy = ams_linux_prod1
policy = intel_class_win2008_2
policy = intel_class_win2008_2
policy = intel_class_win2008_2
policy = intel_class_win2008_2
policy = intel_class_win2008_2
policy = intel_class_win7
policy = intel_class_win2008_2
policy = intel_class_win2008_2
policy = intel_class_win2008_2
policy = intel_class_win2008_2
policy = intel_class_win2008_2
policy = intel_class_win2008_2
policy = intel_class_win2008_2
policy = intel_class_win2008_2
policy = intel_class_win2008_2
policy = intel_class_win2008_2
policy = intel_class_win2008_2
policy = intel_class_win200

Please advise

---------- Post updated at 05:00 PM ---------- Previous update was at 04:34 PM ----------

Hey Hi Pravin,

Can I directly copy paste and run the above given code on command line to get desired output or do I need to create script for that?

Please advise.

Do you mean quit after the first match? Try grep -m1
Do you mean one line per repeating patterns? Pipe result through sort -u
Don't you want to lose the original sort order? Pipe through

awk '!T[$0]++'
1 Like

Hey I came to know, it is really simple, use uniq. ans for my that tiny question :slight_smile:

uniq will work on sorted (or at least entire "paragraphs" with duplicates) files only.

1 Like

Thanks a LOT Pravin27 and RudiC.