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
mfontset_lookup(3m17n)						 The m17n Library					    mfontset_lookup(3m17n)

NAME
mfontset_lookup - Lookup a fontset. SYNOPSIS
MPlist * mfontset_lookup (MFontset * fontset, MSymbol script, MSymbol language, MSymbol charset) DESCRIPTION
Lookup a fontset. The mfontset_lookup() function lookups fontset and returns a plist that describes the contents of fontset corresponding to the specified script, language, and charset. If script is Mt, keys of the returned plist are script name symbols for which some fonts are specified and values are NULL. If script is a script name symbol, the returned plist is decided by language. o If language is Mt, keys of the plist are language name symbols for which some fonts are specified and values are NULL. A key may be Mt which means some fallback fonts are specified for the script. o If language is a language name symbol, the plist is a FONT-GROUP for the specified script and language. FONT-GROUP is a plist whose keys are FLT (FontLayoutTable) name symbols (Mt if no FLT is associated with the font) and values are pointers to MFont. o If language is Mnil, the plist is fallback FONT-GROUP for the script. If script is Mnil, the returned plist is decided as below. o If charset is Mt, keys of the returned plist are charset name symbols for which some fonts are specified and values are NULL. o If charset is a charset name symbol, the plist is a FONT-GROUP for the charset. o If charset is Mnil, the plist is a fallback FONT-GROUP. RETURN VALUE
It returns a plist describing the contents of a fontset. The plist should be freed by m17n_object_unref(). COPYRIGHT
Copyright (C) 2001 Information-technology Promotion Agency (IPA) Copyright (C) 2001-2011 National Institute of Advanced Industrial Science and Technology (AIST) Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License <http://www.gnu.org/licenses/fdl.html>. Version 1.6.2 12 Jan 2011 mfontset_lookup(3m17n)
All times are GMT -4. The time now is 03:05 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy