Закомментируйте разделы текста, которые соответствуют определенным идентификаторам, перечисленным в другом файле

Глядя на диск с рендерингом gdisk:

root@ubuntu-mate:~# gdisk /dev/sda
GPT fdisk (gdisk) version 1.0.1

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): v

Warning: The 0xEE protective partition in the MBR is marked as active. This is
technically a violation of the GPT specification, and can cause some EFIs to
ignore the disk, but it is required to boot from a GPT disk on some BIOS-based
computers. You can clear this flag by creating a fresh protective MBR using
the 'n' option on the experts' menu.

No problems found. 2925 free sectors (1.4 MiB) available in 2
segments, the largest of which is 2014 (1007.0 KiB) in size.

Следуя инструкциям от gdisk:

Command (? for help): ?   
b   back up GPT data to a file
c   change a partition's name
d   delete a partition
i   show detailed information on a partition
l   list known partition types
n   add a new partition
o   create a new empty GUID partition table (GPT)
p   print the partition table
q   quit without saving changes
r   recovery and transformation options (experts only)
s   sort partitions
t   change a partition's type code
v   verify disk
w   write table to disk and exit
x   extra functionality (experts only)
?   print this menu

Command (? for help): r

Recovery/transformation command (? for help): ?
b   use backup GPT header (rebuilding main)
c   load backup partition table from disk (rebuilding main)
d   use main GPT header (rebuilding backup)
e   load main partition table from disk (rebuilding backup)
f   load MBR and build fresh GPT from it
g   convert GPT into MBR and exit
h   make hybrid MBR
i   show detailed information on a partition
l   load partition data from a backup file
m   return to main menu
o   print protective MBR data
p   print the partition table
q   quit without saving changes
t   transform BSD disklabel partition
v   verify disk
w   write table to disk and exit
x   extra functionality (experts only)
?   print this menu

Recovery/transformation command (? for help): x

Expert command (? for help): ?
a   set attributes
c   change partition GUID
d   display the sector alignment value
e   relocate backup data structures to the end of the disk
g   change disk GUID
h   recompute CHS values in protective/hybrid MBR
i   show detailed information on a partition
l   set the sector alignment value
m   return to main menu
n   create a new protective MBR
o   print protective MBR data
p   print the partition table
q   quit without saving changes
r   recovery and transformation options (experts only)
s   resize partition table
t   transpose two partition table entries
u   replicate partition table on new device
v   verify disk
w   write table to disk and exit
z   zap (destroy) GPT data structures and exit
?   print this menu

Expert command (? for help): n

Expert command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): Y
OK; writing new GUID partition table (GPT) to /dev/sda.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot or after you
run partprobe(8) or kpartx(8)
The operation has completed successfully.

Перезагрузитесь, и меня снова встретит rEFInd! Qubes, конечно, больше не загружается.

Кажется, проблема была в защитном mbr, созданном Qubes.

2
25.04.2017, 22:15
3 ответа
while read employeeid; do
    sed --in-place "/$employeeid/s/^/#/" /path/to/App.conf
done < employeeid.txt
1
27.01.2020, 22:03

Предположим, что нет никаких идентификаторов работодателей, которые могли бы быть интерпретированы как допустимые символы регулярного выражения sed , например * , ? или \ :

sed 's:^/export/home/conf\[naa.\('"$(paste -sd '|' employeeid.txt)"'\)\]:#&:' App.conf

Если у вас много идентификаторов работодателей, поэтому итоговая строка становится слишком длинной и ваш sed support -f- (в противном случае вам придется сначала перенаправить его в файл, а затем позволить sed прочитать сценарий):

{
  printf '%s' 's:^/export/home/conf\[naa.\(';
  paste -sd '|' employeeid.txt;
  printf '%s' '\)\]:#&:';
} | tr -d '\n' | sed -f- App.conf

Чтобы внести изменения на месте (изменение файл сразу вместо того, чтобы показывать вам результаты) добавьте -i для GNU sed или -i '' для FreeBSD sed .

1
27.01.2020, 22:03

gawk (GNU awk) подход:

awk 'NR==FNR{a[$1]; next}{match($4, /\[naa\.([0-9A-Z]+)\]/, b); 
     if(b[1] in a) $1="#"$1;}1' OFS="/" employeeid.txt FS="/" App.conf > newfile

Теперь, newfile содержит необходимые строки


a[$1] - накопление массива идентификаторов сотрудников (в качестве индексов), пока первый файл employeeid. txt обрабатывается

FS="/" - разделитель полей для второго файла App. conf

match($4, /\[naa\. ([0-9A-Z]+)\]/, b) - захватывает id сотрудника в 4-м поле строки второго файла

if(b[1] in a) $1="#"$1 - проверяет, находится ли захваченный id сотрудника в массиве crucial. Если да, то добавляет # в первое поле (т.е. в начало строки)

.
1
27.01.2020, 22:03

Теги

Похожие вопросы