0

I have a project that has thousands of code comment blocks like

/**
 * function to do abc
 * and xzy
 *
 * @param ... etc.

and I would like to use a mass find-replace to capitalize the first letter of the first line, so the result is:

/**
 * Function to do abc
 * and xzy
 *
 * @param ... etc.

Is it possible to do this from within PHPstorm? This article suggests the answer is "no." If not I would also welcome a command-line solution using bash.

Community
  • 1
  • 1
Coleman
  • 631
  • 5
  • 13

1 Answers1

1

You can try creating a script and then you positional parameters with the script

my_script.sh  <file with the codes to be change >  <new file with codes start with upp. case>

Assuming your codes in you file is like this:

/**
 * function to do abc
 * and xzy
 *
 * @param ... etc.


/**
 * function to do abc
 * and xzy
 *
 * @param ... etc.


/**
 * function to do abc
 * and xzy
 *
 * @param ... etc.


/**
 * function to do abc
 * and xzy
 *
 * @param ... etc.

create the file my_script and add the codes below inside this file

#!/bin/bash
###remove any existing file that will have the new codes starting with upper case chars ###
rm -f "$2" 2> /dev/null
##let us set up  a while loop that will read the original file that starts with L-case letters####
clue=""
while read -r line; do
if [ "$clue" != "" ]; then 
lower_word=`echo "$line"|tr -s [:space:] ' ' |cut -d ' ' -f2`
upper_word=`echo "$line"|tr -s [:space:] ' ' |cut -d ' ' -f2|sed -e "s/\b\(.\)/\u\1/g"`
new_sentence=`echo "$line"|sed "s/$lower_word/$upper_word/g"`
echo "$new_sentence" >> $2
else
echo "$line" >> $2 
fi
if [ "$line" = "/**" ]; then
clue="/**"
else
clue=""
fi
done < $1

Now run script..your output file should have:

/**
* Function to do abc
* and xzy
*
* @param ... etc.


/**
* Function to do abc
* and xzy
*
* @param ... etc.


/**
* Function to do abc
* and xzy
*
* @param ... etc.


/**
* Function to do abc
* and xzy
*

I apologize for deleting my answer the first time, since I misunderstood your question from the first inception.My apologies I am not a big fan of indentation in bash like I am in python :)

repzero
  • 8,254
  • 2
  • 18
  • 40
  • note also that my codes are based on the fact the you are writting your codes with the pattern "/**" and "*" followed by a space – repzero Dec 02 '14 at 03:08