Ikki satr orasida satrlarni qanday tanlash mumkin

Menda ba'zi buyruqlar chiqaradigan fayl bor.

# cat input.txt

*******************************************************************************
deinstall PREVIEW:  deinstall operation will not actually occur.
*******************************************************************************

+-----------------------------------------------------------------------------+
                    Pre-deinstall Verification...
+-----------------------------------------------------------------------------+
Verifying selections...done
Verifying requisites...done
Results...

FAILURES
--------
  Filesets listed in this section failed pre-deinstall verification
  and will not be removed.

  Dependency Failures
  (Deinstall Operation)
  ---------------------
  SELECTED FILESETS:  The following is a list of filesets that you asked to
  remove.  They cannot be removed until all of their dependent filesets
  are also removed.  See subsequent lists for details of dependents.

    my.data.list 6.1.2.0         # This is my data list...

  INSTALLED DEPENDENTS:  The following filesets are dependents of one or more
  of the selected filesets listed above.  These must be removed before
  or with the filesets that you selected.  To remove these dependents with
  the selected filesets, specify the option to automatically remove dependent
  software (-g flag).

    apple.fruit 6.1.9.200            # This is apple...
    ball.object 6.1.9.200             # This is ball 
    bat.object 6.1.9.200              # This is bat
    cat.animal 6.1.9.200              # this is cat 
    nut.object 6.1.9.200              # this is nut 
    hut.house 6.1.9.200              # this is hut 

  << End of Failure Section >>

FILESET STATISTICS 
------------------
    1  Selected to be deinstalled, of which:
        1  FAILED pre-deinstall verification
  ----
    0  Total to be deinstalled


******************************************************************************
End of deinstall.  No deinstall operation has actually occurred.
******************************************************************************

O'rnatilgan qaramog'imdagi shaxslarning ro'yxatini olish/chop etishga harakat qilaman

apple.fruit 6.1.9.200            # This is apple...
ball.object 6.1.9.200             # This is ball 
bat.object 6.1.9.200              # This is bat
cat.animal 6.1.9.200              # this is cat 
nut.object 6.1.9.200              # this is nut 
hut.house 6.1.9.200              # this is hut 

Ushbu ikkita naqsh orasidagi satrlarni qanday tanlash mumkin? Ikki naqsh o'rtasidagi satrlarni qanday tanlash mumkin?/a> bilan bog'lanish. Va bu buyruq bilan keldi, lekin u ishlamayapti.

Men bu erda noto'g'ri ish qilyapmanmi?

awk '/"software (-g flag)."/ f; /"<< End of Failure Section >>"/{f=0}' input.txt

0

7 javoblar

Dasturni disk ruxsati yoki mashinangizni mexanikaga olib chiqish yoki itni veterinar shifokorlariga tashlash uchun yordam so'raganingizda, hech qachon " ishlamaydi deyman. Yordam olishning eng yaxshi imkoniyatiga ega bo'lish uchun har doim "ishlamayotgan" banddagi alomatlar haqida tavsif bering, masalan. noto'g'ri chiqishi, chiqishi, yadrosi, xato xabarlari, boshqa narsalar (ba'zi birlar it holida qo'llanilmaydi :-)).

Buni aytgan:

  1. the start/end lines in your file are not surrounded by double quotes so don't ask your script to match on them, and
  2. (, ) and . are regexp metacharacters so if you want them treated literally you have to escape them.

Buni ko'ring:

awk '/software \(-g flag\)\./ f; /<< End of Failure Section >>/{f=0}' input.txt

keyin uni quyidagicha o'zgartiring:

awk '/software \(-g flag\)\./ f && NF; /<< End of Failure Section >>/{exit}' input.txt

bo'sh satrdan qutilish va samaradorlik uchun.

3
qo'shib qo'ydi

@Albert: Sinash:

awk '/End of Failure Section/{A=""} /software \(-g flag\)/{A=1;next} A && !/^$/{print}'   Input_file

Explanation: Checking if a line is having string (software (-g flag)) if yes then making a variable named A to TRUE, if a line is having string (End of Failure Section) then make variable named A's value to 0. then check if variable A's value is TRUE/ONE and line is NOT NULL then print the current line.

2
qo'shib qo'ydi

Sababi taglik borligi sababli:

sed -n '/software (-g flag)/,/<< End of Failure Section/{//!p}' input.txt
1
qo'shib qo'ydi
$ awk '
       /software \(-g flag\)/{ f=1; next }
       /<< End of Failure Section >>/{f=0}
       f && NF
      ' file

Sharh

$ awk '                                       # call awk
       /software \(-g flag\)/{ f=1; next }    # look for regex in record, if found set var f=1 and got to next line
       /<< End of Failure Section >>/{f=0}    # look for regex if found then set var f to 0
       f && NF                                # if f and NF then print record, this is to skip empty lines
      ' file
1
qo'shib qo'ydi

awk bilan yana bir yechim:

awk '/INSTALLED DEP/{a=1} a&&/^$/{b=1;a=0;next} b{print} b&&/^$/{b=0}' File

    apple.fruit 6.1.9.200            # This is apple...
    ball.object 6.1.9.200             # This is ball
    bat.object 6.1.9.200              # This is bat
    cat.animal 6.1.9.200              # this is cat
    nut.object 6.1.9.200              # this is nut
    hut.house 6.1.9.200              # this is hut
1
qo'shib qo'ydi
sed '/software (-g flag)./,/End of Failure Section/!d;//d' input.txt
1
qo'shib qo'ydi

Boshqa usul regex mosligini mos keladigan naqshlarni o'z ichiga olgan yozuvlarni chop qilish uchun ishlatadi:

$ awk '/([a-z][. ])+([0-9].?)+/' file
    my.data.list 6.1.2.0         # This is my data list...
    apple.fruit 6.1.9.200            # This is apple...
    ball.object 6.1.9.200             # This is ball 
    bat.object 6.1.9.200              # This is bat
    cat.animal 6.1.9.200              # this is cat 
    nut.object 6.1.9.200              # this is nut 
    hut.house 6.1.9.200              # this is hut 

Regex above is no means perfect, for example the first outputed record should not be there and should be weeded out adding for example && !/my./ to the condition:

$ awk '/([a-z][. ])+([0-9].?)+/ && !/my./' file
0
qo'shib qo'ydi