Wednesday, September 9, 2020

Add text at the beginning of each line on linux

adding # at the beginning of every line in a text file.

[root@master ~]# cat /tmp/a
  179  ls -l /opt/OS_Image/BaseOS/repodata/repomd.xml
  180  vi /etc/yum.repos.d/rhel8.repo
  181  yum search cockpit
  182  yum install cockpit
  183  systemctl status cockpit
  184  systemctl status cockpit.socket
  185  systemctl enable --now cockpit.socket
  186  systemctl status cockpit
  187  systemctl status cockpit.socket
  188  ifconfig
  189  ip a s
  190  su - sam
  192  service auditd rotate
  193  service auditd rotate 2>&1 | /bin/sed -r "s/\x1B\[([0-9]{1,2}(; [0-9]{1,2})?[m|k]//g"
  194  pwd
  195  clear
  196  vi /tmp/a

[root@master ~]# cat /tmp/a | awk '{first = $1; $1 = " "; print "#" $0 }'
#  ls -l /opt/OS_Image/BaseOS/repodata/repomd.xml
#  vi /etc/yum.repos.d/rhel8.repo
#  yum search cockpit
#  yum install cockpit
#  systemctl status cockpit
#  systemctl status cockpit.socket
#  systemctl enable --now cockpit.socket
#  systemctl status cockpit
#  systemctl status cockpit.socket
#  ifconfig
#  ip a s
#  su - sam
#  service auditd rotate
#  service auditd rotate 2>&1 | /bin/sed -r "s/\x1B\[([0-9]{1,2}(; [0-9]{1,2})?[m|k]//g"
#  pwd
#  clear
#  vi /tmp/a
#
[root@master ~]#
 

Move first field to last and everything on same position.

[root@master ~]# cat /tmp/a | awk '{first = $1; $1 = " "; print "#" $0, first; }'
#  ls -l /opt/OS_Image/BaseOS/repodata/repomd.xml 179
#  vi /etc/yum.repos.d/rhel8.repo 180
#  yum search cockpit 181
#  yum install cockpit 182
#  systemctl status cockpit 183
#  systemctl status cockpit.socket 184
#  systemctl enable --now cockpit.socket 185
#  systemctl status cockpit 186
#  systemctl status cockpit.socket 187
#  ifconfig 188
#  ip a s 189
#  su - sam 190
#  service auditd rotate 192
#  service auditd rotate 2>&1 | /bin/sed -r "s/\x1B\[([0-9]{1,2}(; [0-9]{1,2})?[m|k]//g" 193
#  pwd 194
#  clear 195
#  vi /tmp/a 196
#

[root@master ~]#


No comments:

Post a Comment

Git branch show detached HEAD

  Git branch show detached HEAD 1. List your branch $ git branch * (HEAD detached at f219e03)   00 2. Run re-set hard $ git reset --hard 3. ...