logo
down
shadow

Bash Script to Comment/uncomment lines in file


Bash Script to Comment/uncomment lines in file

By : Jessica Goel
Date : November 15 2020, 06:54 AM
it helps some times The following script will allow you to "turn on" and "turn off" specific lines. In your case, it will "turn off" all lines containing machine-2 and "turn on" lines containing machine-1. The script is as follows:
code :
comm=$1
uncomm=$2
filename=$3
sed -i -e "/$comm/s/^;*/;/" $filename
sed -i -e "/$uncomm/s/^;//" $filename
./scriptname machine-2 machine-1 configurationFileName.conf


Share : facebook icon twitter icon
Bash script to pull out x number of starting comment lines into another file

Bash script to pull out x number of starting comment lines into another file


By : Danny
Date : March 29 2020, 07:55 AM
I hope this helps you . I am looking for a one liner to pull out the first comment block in any file. The comment blocks look like this:
code :
sed -n '/^\/\*/,/^ \*\//p;/^ \*\//q' file
sed -n '\|^/\*|,\|^ \*/|p;\|^ \*/|q' file
sed -n '\|^/\*.*\*/|{p;q};\|^/\*|,\|^ \*/|p;\|^ \*/|q' file
sed -n '\|^[[:space:]]*/\*.*\*/|{p;q};\|^[[:space:]]*/\*|,\|^ \*/|p;\|^[[:space:]]*\*/|q'
vim: comment/uncomment all lines in file containing a string

vim: comment/uncomment all lines in file containing a string


By : Mark Yendt
Date : March 29 2020, 07:55 AM
I wish this help you The :global/{pat}/{cmd} command will run a command, {cmd}, on every line matching pattern, {pat}. You can execute your tComment command via the :normal command. All together it looks like this:
code :
:g/@login_required/norm gcc
:h :g
:h :norm
vim 7.4 comment/uncomment lines in Vim without plugins

vim 7.4 comment/uncomment lines in Vim without plugins


By : jezpac
Date : March 29 2020, 07:55 AM
hop of those help? There are many ways to comment/uncomment in Vim. Anyway, assuming "C++-style" comments, eg. // foobar…
Commenting a single line
code :
I// <Esc>
^dw
vjjj
:'<,'>norm! I// <CR>
<C-v>jjj
I// <Esc>
vjjj
:'<,'>norm! ^dw<CR>
<C-v>jjjllld
Is it possible to comment/uncomment tags inside an xml file using xmlstarlet or other bash tools

Is it possible to comment/uncomment tags inside an xml file using xmlstarlet or other bash tools


By : Charan teja
Date : March 29 2020, 07:55 AM
wish of those help After playing with xlstproc, i come up with a solution for uncommenting case. 'contains' function does the trick...
code :
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <!--Identity template,
   provides default behavior that copies all content into the output -->
   <xsl:template match="@*|node()">
       <xsl:copy>
           <xsl:apply-templates select="@*|node()"/>
       </xsl:copy>
   </xsl:template>
   <!--More specific template for "from" that provides custom behavior -->
   <xsl:template match="comment()">

       <xsl:if test='contains(.,"&lt;from&gt;")' >
           <xsl:value-of  select="." disable-output-escaping="yes" />
       </xsl:if>

       <xsl:if test='not (contains(.,"&lt;from&gt;"))' > 
           <xsl:copy-of select="." />
       </xsl:if>

   </xsl:template>
</xsl:stylesheet>
Nodejs script to uncomment some lines of code or replace a comment with contents from a file

Nodejs script to uncomment some lines of code or replace a comment with contents from a file


By : user2235946
Date : March 29 2020, 07:55 AM
Does that help working codepen (including more block comments, etc.): https://codepen.io/Frederic-Klein/pen/KbXxeB?editors=0012
Example code for matching and replacing the given example using regular expressions with capturing (...) and non-capturing (?:...) groups for the replacements with inline explanations:
code :
const content = `
/* api_start ====
app.use('/api',require('./api/api'));
app.use('/sms',require('./api/sms'));
==== api_end */
// app.use('/api',require('./api/api'));
// app.use('/sms',require('./api/sms'));
`;

const regex_block_comments = /^\/\*.*\n((?:app.*\n)*)(?:.*\*\/\n)/gm;
// match lines
// starting with /*
// having the following lines start with app, capture all those lines as one group ($1 reference)
// having a line ending with */ afterwards, as non-capturing group
// repeat globally (g) and match multiline (m) string

const regex_comment = /^\/\/\s*(app.*;\n)/gm;
// match lines
// starting with //
// ignore following whitespaces
// having text "app" afterwards, capture from app to line-ending as group ($1 reference)

const replacement = `$1`;

newcontent = content.replace(regex_block_comments,replacement);
newcontent = newcontent.replace( regex_comment,replacement);

// content after replacements
console.log(newcontent);
Related Posts Related Posts :
  • syslog Log/ Event generator linux
  • Ping timeout issues
  • How make /var/www contents editable by IDE
  • Why ordinary user cannot use chgrp/chown
  • Execute a script on startup of SUSE reboot
  • Extracting debugging information from core files
  • linux command to connect to another server using hostname and port number
  • GLib.Settings.changed event not firing
  • What does it mean by code holding semaphore can be preempted
  • Does LD_LIBRARY_PATH really cause inconsistencies?
  • "lsof" shows a file as (deleted) but I can still see it in file system
  • Linux file deleted recovery
  • Exchange columns in bash
  • How to set max file size in Linux CeNTOS to server.log
  • Regular expressions: Search a word and append a new word at the end of the line
  • Compress a set of log files in a folder depending on number of files
  • unexpected behavior of linux malloc
  • relation between init and bash terminal process
  • Matlab VideoReader codec error?
  • How to catch the L3-cache hits and misses by perf tool in Linux
  • Executable Deleting Itself on linux
  • How to change the apache httpd port for serving files
  • Installing Patches in linux
  • Comparative analysis between libkvm on linux and NetBSD
  • How to join multiple txt files into based on column?
  • setting LINK variable in Makefile generated by qmake (5.0)
  • Automake - difficulty with installing version 'automake-1.14.1'
  • How to use Linux Network Namespaces for per processes routing?
  • How can I write a Gruntfile with different shell command behaviour for OS X vs. Linux?
  • Using at command in shell script for scheduling a command
  • Is there a method to figure out the audio channel layout in Linux?
  • Setting environment varilable for daemon / root process
  • string replacement in shell script
  • Add specific column to the end of a CSV file
  • Are there programmable automount/autofs hooks in linux/systemd?
  • Renaming files like 20141207_190822.jpg to "2014-12-07 19.08.22.jpg" in linux or MacOS X
  • undocumented kernel boot parameter?
  • using wget to mirror a website with path and subfolder that have the same name
  • Using awk to find data matching date range in text file
  • Installing xorg-x11-devel package in SLES 11 SP2
  • Setting result of find to variable, which has variables within it
  • Maximum/Minimum physical address - Linux kernel
  • Freepbx custom context outbound route
  • memcpy implementation in linux kernel
  • How to reverse a list of words in a shell string?
  • Concatenate and pass as parameter in bash
  • Add user to Docker container
  • How to add a content in a file in linux without opening the file using vi or cat command
  • Which SVN subversion can I use on linux, Mac, Windows?
  • Work with ZIP archive at Bash
  • bash script not running as expected from cron vs. shell.
  • Compare one field, Remove duplicate if value of another field is greater
  • sudoers NOPASSWD: sudo: no tty present and no askpass program specified
  • How do I use pipes and variable substitution in a shell script (for toggling haproxy active server)?
  • Linux/Unix Find Command
  • Not able to copy data in hdfs with hdfs dfs commands
  • Linux : Remove/Delete .txt files ending with exactly five digits
  • ARM assembly "retne" instruction
  • Migrate from LXC to LXD
  • sbt on linux not accepting -jvm-debug 5005
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org