Tag Archives: Bash

Count number of lines in a text file

wc -l file_name

Tagged , | Leave a comment

Extract Lines From a Text File

“sed -n 2,4p file_name” extracts lines from 2 to 4 from that file

Tagged , | Leave a comment

How To Write Infinite Loop in Bash

This is how you create an infinite loop in bash to run a piece of code infinitely at defined intervals. #!/bin/bashwhile [ 1 ]do # Your code goes here # Modify sleep time (in seconds) as needed below sleep 2done … Continue reading

Tagged | Leave a comment

find files and copy them to a certain folder in bash (draft)

find . -name “*” | grep -i scomm | xargs ls -ltr | grep “Aug 13 10” | awk ‘{print $9}’ to use in the cp command (get the column number 9 which contains the file’s full path cp `find … Continue reading

Tagged , , | Leave a comment

How to search for a string inside multiple text files

find starting_folder -name “*” | grep -i file_name | xargs grep -i search_string for example: “find . -name “*” | grep -i hobba | xargs grep -i tito” searches for the string “tito” inside all files whose name contains the … Continue reading

Tagged , , | Leave a comment