I need to calculate md5sum of one string (pathfile) per line in my ls dump, directory_listing_file:
./r/g4/f1.JPG ./r/g4/f2.JPG ./r/g4/f3.JPG ./r/g4/f4.JPG   But that md5sum should be calculated without the initial dot. I've written a simple script:
while read line do     echo $line | exec 'md5sum' done  ./g.sh < directory_listnitg.txt   How do I remove the first dot from each line?
To remove the first and last character of a string, we can use the parameter expansion syntax ${str:1:-1} in the bash shell. 1 represents the second character index (included). -1 represents the last character index (excluded). It means slicing starts from index 1 and ends before index -1 .
Remove Character from String Using trThe tr command (short for translate) is used to translate, squeeze, and delete characters from a string. You can also use tr to remove characters from a string.
Removing the first n characters To remove the first n characters of a string, we can use the parameter expansion syntax ${str: position} in the Bash shell.
myString="${myString:1}"   Starting at character number 1 of myString (character 0 being the left-most character) return the remainder of the string. The "s allow for spaces in the string. For more information on that aspect look at $IFS.
You can pipe it to
cut -c2-   Which gives you
while read line do echo $line | cut -c2- | md5sum done  ./g.sh < directory_listnitg.txt 
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With