Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

#Commands:

1.grep:
(i)Search for a specific word or pattern in a file
grep -i 'pattern' filename
(ii)filter & extract specific information from a file
Name: John
Age: 30
City: New York

Name: Alice
Age: 25
City: Los Angeles

Name: Bob
Age: 35
City: Chicago

# Filter lines containing "Name" from data.txt


grep "Name" data.txt

# Filter lines containing "Age" from data.txt


grep "Age" data.txt

# Extract names (2nd column) from data.txt


awk '/Name/{print $2}' data.txt

# Extract ages (2nd column) from data.txt


awk '/Age/{print $2}' data.txt

ii)grep -o . filename: to split the filtered input into individual characters.


grep -o . matches each character and prints it on a separate line.
2.cut
(i)extract coloumns
cut -f 2 -d $':' panic.txt
ekhane : jukto ongsho k ekta coloumn ar tar previous & porer part tukun alda alda
colomn dhorbe. then f1 naki f2 naki f3 oi onujai koto no. colomn sheita show
korbe..obosshoi line by line jabe so jei line gulan e : nai oigula purata print
hobe
3.find
(i)Use `find` to locate all files with a specific extension in a directory and its
subdirectories.
find /directory -type f -name "*.txt"
.txt wala shob file dekhabe, ekhon jodi chao koyta tyle aager command er j o/p
oigli shb line koyta gunlei oi shongkhok file pao
so,
find /directory -type f -name "*.txt" | wc -l
(ii)redirect the output of find in another file
# Using > to Redirect Output (Overwrite):
find "$directory" -type f -name "*.txt" > output.txt
Using >> to Redirect Output (Append):
find "$directory" -type f -name "*.txt" >> output.txt
4.tr:
(i)# Use tr to delete all lowercase letters (a-z) from a file
tr -d 'a-z' < input.txt
(ii)convert lower case characters to upper case
cat greekfile | tr [a-z] [A-Z]
****
To display the first 20 characters of an input file using the head command, you can
use the following command:
head -c 20 input.txt

You might also like