How do I remove the file suffix and path portion from a path string in Bash?

Here’s how to do it with the # and % operators in Bash. $ x=”/foo/fizzbuzz.bar” $ y=${x%.bar} $ echo ${y##*/} fizzbuzz ${x%.bar} could also be ${x%.*} to remove everything after a dot or ${x%%.*} to remove everything after the first dot. Example: $ x=”/foo/fizzbuzz.bar.quux” $ y=${x%.*} $ echo $y /foo/fizzbuzz.bar $ y=${x%%.*} $ echo $y … Read more

Reading a file line by line in Go

In Go 1.1 and newer the most simple way to do this is with a bufio.Scanner. Here is a simple example that reads lines from a file: package main import ( “bufio” “fmt” “log” “os” ) func main() { file, err := os.Open(“/path/to/file.txt”) if err != nil { log.Fatal(err) } defer file.Close() scanner := bufio.NewScanner(file) … Read more

How can I use grep to find a word inside a folder?

grep -nr ‘yourString*’ . The dot at the end searches the current directory. Meaning for each parameter: -n Show relative line number in the file ‘yourString*’ String for search, followed by a wildcard character -r Recursively search subdirectories listed . Directory for search (current directory) grep -nr ‘MobileAppSer*’ . (Would find MobileAppServlet.java or MobileAppServlet.class or … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)