4th Street Bar Hive-Bar

Hive-Bar Powered by Hive beta-fdb5b5b

Community post

Text Processing In LINUX - With Examples

If you know how to get in touch with Linux, it is always easier to manage services based on it rather than Windows.
to get to that point today I am going to show you some commands that can be useful at its time. this way I review thing too which is good for me as well :)

I will focus on text processing commands for now

1. basename

basename is very useful when you are writing a script and you need to seperate the file name from the path, in this case you can easyl type 'basename /path/to/file' and it will return the file name.

![](https://steemitimages.com/DQmf7Yt4KxXaU2AV8ERk1K4grJyh8B75Vk7ga2amJtvH1Uf/image.png)

2.comm

with comm command you can compare two files and their columns. in this example it says both have number1, file1 has number 2, file 2 has number3 and number4 and it goes like this. give it a try and play with it, it could be in use sometimes specially if you want to work with financial data

![](https://steemitimages.com/DQmPT2txZs7GNkNacHE7t8pZv3qRidrcPTZuc4NegQU3uje/image.png)
### 3. csplit While working on the command line in Linux, you may need to split a file into multiple parts, in that case csplit is what you are looking for in this example I am splitting the file from line 2 and I am repeating this pattern 3 times
![](https://steemitimages.com/DQmPheXQjxtsoppAWZxNzDNV3UoazWVPWMFevhYk8ZuiJ6g/image.png)
I can do other things as well, like giving a prefix to the created files , etc... ### 4. diff imagine you are copying a very important file in other directory and you wanna make sure the file is the right one, by command 'diff' you can easily make sure your filed don't differ diff file1 file2
![](https://steemitimages.com/DQmPE1gb3EjS6y7sSro84FqPUSu7pfMoFnetfKyL6QSRqsv/image.png)
### 5. dirname direname is opposite of basename, meaning it will return path to the file dirname /tmp/peer/file1
![](https://steemitimages.com/DQmbasPWji97Uumg3cMNnZnRg8StrGYVsRDd8U2ZLLDwNde/image.png)
### 6. fmt with fmt you can make some texts more readable, like putting them in one line, changing the length of line, etc fmt filename you can see different options here
![](https://steemitimages.com/DQmaZbHkJVckM7fpSG7qK7R7xDm7Ews64DHUDvE53aA1tbe/image.png)
### 7. Head with head you can choose to show how many lines, bytes, etc of file head -10 file4 #will show 10 first lines of file 4
![](https://steemitimages.com/DQmSZVSdFEurQ89K4uqh5uknv4piqE1y7KXaHZ7TPWHjSTn/image.png)

8. tail

with tail you can choose to show how many lines, bytes, etc of file
tail -10 file4 #will show 10 last lines of file 4

![](https://steemitimages.com/DQmTxQ2YXt16jcuJmckYmJxdjHjfbsEivs9L3E7vemBZovX/image.png)
also tail -f will show changes in file online and you can grep it to show specific string tail -f file4 | grep "error in file"
![](https://steemitimages.com/DQme31eq2WcenwtQanuGkfvqU77mCavsWfBNjTvhLTuMbFi/image.png)
### 9. wc with this command you can get the number of lines, words, letters of a file wc -l file4 # will give you number of lines in file4
![](https://steemitimages.com/DQmXzC1tRLh1qngriWY3dNYa8RmEAhgwtvLh5m1EARSu5Xa/image.png)
some other options of wc command
![](https://steemitimages.com/DQme1Q19J17WpfA7Qm3ec5dJEyHA5CCpkF7ACYQYk1bt7db/image.png)
###
I hope you find it useful, in next post I will show you guys some other commands that I find useful
###
thanks for your support
3 upvotes $0.03

Replies (2)

Review before signing

Posting as . Signing with . Keychain permission: Posting. Hive Keychain will ask you to approve this action next.


  
Technical details

Operation fingerprint: