Sponsored Content
Top Forums Shell Programming and Scripting Perl one liner to wrap comment lines Post 302927918 by junior-helper on Sunday 7th of December 2014 10:12:05 AM
Old 12-07-2014
It's doable, but then the one-liner would no longer be a one-liner, imho.

You might find following alternative viable/useful
Code:
#!/bin/bash

pVersion="$1"
pChangeLog="$2"


perl -spi -e "s/version=\"*.*.*.*\"/version=\"$pVersion\"/g" somescript.sh

if [ ${#pChangeLog} -gt 71 ] # 80 - 8 spaces from tab - 1 hypen
then    # wrapping necessary

MLINE=$(
    # first line
    line="${pChangeLog:0:71}"
    printf "#\t-%s\n" "$line"
    pChangeLog="${pChangeLog:71}"

    # all the rest
    while [ ${#pChangeLog} -gt 0 ];
    do
        line="${pChangeLog:0:64}" # 80 - 16 spaces from two tabs
        printf "#\t\t%s\n" "$line"
        pChangeLog="${pChangeLog:64}"
    done
)

    perl -spi -e "s/change\ log/change\ log\n#\t$pVersion\n$MLINE/g" somescript.sh

else    # fits in one line

    perl -spi -e "s/change\ log/change\ log\n#\t$pVersion\n#\t-$pChangeLog/g" somescript.sh

fi

Demo:
Code:
$ cat somescript.sh
#!/bin/coolcli

# version="w.x.y.z"
# change log

# <------ program code below this line  ------>
$
$ ./update.sh 0.0.0.1 "first version"
$ ./update.sh 0.0.0.2 "added function x"
$ ./update.sh 0.0.1.0 "some text"
$ ./update.sh 0.0.1.1 "some more text"
$ ./update.sh 0.1.0.0 "A changelog is a log or record of changes made to a proje
ct, such as a website or software project, usually including such records as bug
 fixes, new features, etc. Source: wikipedia"
$ 
$ cat somescript.sh
#!/bin/coolcli

# version="0.1.0.0"
# change log
#       0.1.0.0
#       -A changelog is a log or record of changes made to a project, such as a 
#               website or software project, usually including such records as b
#               ug fixes, new features, etc. Source: wikipedia
#       0.0.1.1
#       -some more text
#       0.0.1.0
#       -some text
#       0.0.0.2
#       -added function x
#       0.0.0.1
#       -first version

# <------ program code below this line  ------>
$

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to comment multiple lines in unix

hi all, please help me how to comment multiple lines in unix script. thanks in advance --bali (3 Replies)
Discussion started by: balireddy_77
3 Replies

2. Shell Programming and Scripting

Perl One Liner

Hi , Can anybody explain how this perl one liner works.. It is to test whether the number is prime or not perl -le 'print "PRIME" if (1 x shift) !~ /^(11+)\1+$/' 19 Thanks in advance Shihab (2 Replies)
Discussion started by: shihabvk
2 Replies

3. UNIX for Dummies Questions & Answers

comment lines

Is there a command to put a comment (#) in a whole part of a shell script? (5 Replies)
Discussion started by: vero_81
5 Replies

4. Shell Programming and Scripting

Wrap lines with awk to create SQL script

Greetings! Some of my files list hardware errors (we test electronic components), some have none. If the file name has no errors, I still want to display a message like "No error", else I display the error from the file itself. I came up with this (with help) for myfile in `find . -name... (2 Replies)
Discussion started by: alan
2 Replies

5. Shell Programming and Scripting

Search & Replace regex Perl one liner to AWK one liner

Thanks for giving your time and effort to answer questions and helping newbies like me understand awk. I have a huge file, millions of lines, so perl takes quite a bit of time, I'd like to convert these perl one liners to awk. Basically I'd like all lines with ISA sandwiched between... (9 Replies)
Discussion started by: verge
9 Replies

6. Shell Programming and Scripting

How can i comment out a section between two particular lines

I want to find out which files under /etc have the the following section: and then i would like to comment out the above section in all the files. Please help. (3 Replies)
Discussion started by: proactiveaditya
3 Replies

7. Shell Programming and Scripting

Comment lines in FSTAB using perl

Hi All, I need to comment specific Two Lines in fstab & want to do using & also want to ensure that is done corretly. I am trying the below method. But its giving Search pattern not terminated. ################ b36376 67 % cat linux-fstab_testing | perl -i -wnl -e '/^('\Q... (1 Reply)
Discussion started by: ajaincv
1 Replies

8. Shell Programming and Scripting

Comment ( -- ) lines from 10 to 25 for every .sql file

Platform : RHEL 5.4 I have several .sql files in a directory. I want to comment lines 10 to 25 for all .sql files. How can I do this ? The symbol for comment in SQL is -- eg: -- select salary from emp where empname = 'URS' ; (3 Replies)
Discussion started by: omega3
3 Replies

9. UNIX for Dummies Questions & Answers

Bash does not wrap long lines correctly

Ksh is my default shell, but I want use the bash shell since its convenient to me. When I type a long command line in a terminal, it does not wrap to the next line when I reach the end of the line and it wraps onto the same line, overwriting my prompt and the rest of what I typed. $... (5 Replies)
Discussion started by: senthil.ak
5 Replies

10. Shell Programming and Scripting

PERL one liner

hi, I am using PERL one liner for oracle database connection as : $PERL -e "use DBI; DBI->connect(qw(DBI:Oracle:SID user passwd));" is there a way to append select statement to this connection ? i.e. DB connection and select stmt in one line ? how to do sysdba connection using one lines... (1 Reply)
Discussion started by: talashil
1 Replies
WRAP-AND-SORT(1)					      General Commands Manual						  WRAP-AND-SORT(1)

NAME
wrap-and-sort - wrap long lines and sort items in Debian packaging files SYNOPSIS
wrap-and-sort [options] DESCRIPTION
wrap-and-sort wraps the package lists in Debian control files. By default the lists will only split into multiple lines if the entries are longer than 80 characters. wrap-and-sort sorts the package lists in Debian control files and all .install files. Beside that wrap-and-sort removes trailing spaces in these files. This script should be run in the root of a Debian package tree. It searches for control, control.in, copyright, copyright.in, install, and *.install in the debian directory. OPTIONS
-h, --help Show this help message and exit. -a, --wrap-always Wrap all package lists in the Debian control file even if the entries are shorter than 80 characters and could fit in one line line. -s, --short-indent Only indent wrapped lines by one space (default is in-line with the field name). -b, --sort-binary-packages Sort binary package paragraphs by name. -k, --keep-first When sorting binary package paragraphs, leave the first one at the top. Unqualified debhelper(7) configuration files are applied to the first package. -n, --no-cleanup Do not remove trailing whitespaces. -d path, --debian-directory=path Location of the debian directory (default: ./debian). -f file, --file=file Wrap and sort only the specified file. You can specify this parameter multiple times. All supported files will be processed if no files are specified. -v, --verbose Print all files that are touched. AUTHORS
wrap-and-sort and this manpage have been written by Benjamin Drung <bdrung@debian.org>. Both are released under the ISC license. DEBIAN
Debian Utilities WRAP-AND-SORT(1)
All times are GMT -4. The time now is 11:08 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy