Tag: string

Replacing in Found Files

Replace one string by another in all file found by find. find . -name *whatyouwant* -exec perl -pi.bak -e ‘s/TEXT_TO_REPLACE/TEXT_TO_REPLACE_IT_WITH/g’…

Random Password in PHP

A simple way to create a random password in PHP $password = substr(md5(time()), 0, rand(4,8));

Seach for a String in a Folder using grep

Search string “test_text” at directory ‘/var/log’ and below grep test_text -R /var/log/*

Using M4 Command

This command takes an input file and substitutes strings inside it with the parameters passed, similar to substituting for variables….

Command to Print Until Regular Expression

Print a file until a regular expression is matched. cat file.txt | perl -pe “exit if(/Thats all/)”

Fetch columns of Output using Awk

One can use awk to get a specific column from a command output… First column of the command date|awk ‘{print…

Replace \n with another String

The command to convert all \n in a file to another string – very useful for list code generation. perl…

Searching text in a directory using find and grep

Use find and grep to search for a specific text in a directory. In this example, we search for files…

Command to Replace a String in all Files in Current Directory

Replaces all instance of ‘<old string>’ with ‘<new sting>’ in all the files of the current directory. perl -pi -e…