source: other-projects/gti/remove_extra_lines_glihelp.sh@ 32022

Last change on this file since 32022 was 30846, checked in by ak19, 8 years ago

Wrong module in script name.

  • Property svn:executable set to *
File size: 2.4 KB
Line 
1#! /bin/bash
2
3cp $1 $1.bak
4
5CLEANVERSION_NAME="$1.clean"
6
7# echo $1
8
9# Removing lines that will become completely empty after sed operation
10# http://soft.zoneo.net/Linux/remove_empty_lines.php
11# http://www.grymoire.com/Unix/Sed.html#uh-30
12sed '/ *# -- Missing translation/d' $1 > $CLEANVERSION_NAME
13mv $CLEANVERSION_NAME $1
14
15# Now we got rid of all the empty lines created by removing "Missing translation" lines
16# We remove any lines containing "Missing translation" but also containing other stuff
17
18cat $1 | sed -e 's/# -- Missing translation:.*$//' > $CLEANVERSION_NAME
19
20# Remove comment of form: #Updated 21-Nov-2011 by <name>
21# The date can be either 1 or 2 digits. It need not be followed by "by <name>"
22#cat $CLEANVERSION_NAME | sed -e 's/# Updated \d\d-[a-zA-Z]{3}-\d{4} by.*$//' > $1
23#cat $CLEANVERSION_NAME | sed -e 's/ *# Updated .* (by.*)?$//' > $1
24cat $CLEANVERSION_NAME | sed -e 's/ *# Updated .[0-9]*\-...\-.....*$//' > $1
25
26
27# Process gli/help/<lang>/help.xml files by removing Missing and Updated xml elements:
28# <Updated date="dd-mmm-yyyy by someone"/>
29# <!-- Missing translation: \d\d\d -->
30cat $1 | sed -e 's@<Updated date=\"[^\"]*\"\/>\s*@@' > $CLEANVERSION_NAME
31# remove empty lines introduced into the file
32# http://stackoverflow.com/questions/14570489/how-to-remove-blank-lines-from-a-unix-file
33# Note: need to escape the plus sign (the regex symbol for one or more chars)
34cat $CLEANVERSION_NAME | sed -e 's@<!\-\-\s*Missing translation:\s*[^ ]\+ \+\-\->@@' | sed '/^$/d' > $1
35
36
37# To test if there were ultimately no relevant changes, work on the temporary *.clean file:
38# remove all lines that are merely empty/spaces
39# and any lines that are purely comments (though these may start with spaces)
40# Then test if the *.clean file is non-empty at the end of it
41# double sed operation to remove all comments and then all empty lines:
42# http://stackoverflow.com/questions/22080937/bash-skip-blank-lines-when-iterating-through-file-line-by-line
43#cat $1 | sed -e 's/^\s*(#.*)$//' > $CLEANVERSION_NAME
44sed -e '/\s*#.*$/d' -e '/^\s*$/d' $1 > $CLEANVERSION_NAME
45
46# if the *.clean file is actually empty, print a message
47# http://www.unix.com/shell-programming-and-scripting/21753-check-if-file-empty.html
48if [[ ! -s $CLEANVERSION_NAME ]] ; then
49 echo "@@@ $1 only has comments and empty lines/spaces."
50fi ;
51rm $CLEANVERSION_NAME
52
53
54echo "**** cleaned version $1"
55echo "**** pre-cleaned original is in $1.bak"
Note: See TracBrowser for help on using the repository browser.