Skip to main content

Commands: Cut


Example Text
Example Text

Select Column

Cut command provides ability to select specified column according to character number for all rows. Here we will print all rows 3 character line by line to the console. This will only print single character.
Select Column
Select Column

Select Column For Character Range

In previous example we have printed single character to the terminal. We can also print multiple characters to the console by specifying character range like below. We can see that character index starts from 1.
Select Column For Character Range
Select Column For Character Range

Select Column Using Start Position

Another useful feature of cut is specifying only start position up to end.
Select Column Using Start Position
Select Column Using Start Position

Select Column Using End Position

We can print range from start to the specified position only specifying end position. This will assume start position as 1
Select Column Using End Position
Select Column Using End Position

Select Single Field

Field is some part of text delimited with specific characters like space,tab, double comma etc. We can select text with field number. By default field delimiter is tab. Our text is all ready provides tab for delimitation. In this example we will select 3. field.


Select Single Field
Select Single Field

Select Multiple Fields

As we do in characters we can also specify field range. We will select fruit names and counts with the following command.
Select Multiple Fields
Select Multiple Fields
Following example selects more than one field one by one not using ranges.
Select Multiple Fields
Select Multiple Fields

Last Field

One of most popular usage of cut is printing last field. The problem is that field count may change according to text and we can not specify last field only using cut command. Following example uses rev command to get last field.
Last Field
Last Field

Select Fields Include Specified Chars

By default cut do not have the ability to exclude lines acorrding to characters but grep can be used easily to implement this feature. We will only select rows contain app
Select Fields Include Specified Chars
Select Fields Include Specified Chars

Select Fields Except Specified Chars

We can reverse the previous example and remove unwanted rows. We will remove lines contains app and then print columns from 1 to 2 .
Select Fields Except Specified Chars
Select Fields Except Specified Chars

Specify Delimiter

Delimiter is used to divide fields. By default tab is used as delimiter. But it can be specified with -d option like below. Following example we use : as delimiter because the passwd file uses it. Then we only want to show user names those resides in field 1.

Specify Delimiter
Specify Delimiter

Print Except Fields

As we see previously fields can be printed as ranges too. We can also print by excepting fields. This will print all renaming fields. Following example we can want to print all fields except 2 .

Change Delimiter

Text may have delimiters by default. In some situations we may want to change delimiter while printing to the console. --output-delimiter option can be used for this operation. Following example will change tab delimiter to the comma.
Change Delimiter
Change Delimiter

Comments

Popular posts from this blog

VM 9 : PHP Include And Post Exploitation

Walkthrough 1.        https://medium.com/@Kan1shka9/pentesterlab-php-include-and-post-exploitation-walkthrough-8a85bcfa7b1d 2.        Ine [] 3.        http://megwhite.com.au/pentester-lab-bootcamp-walkthrough-php-include-post-exploitation/ 4.        http://fallensnow-jack.blogspot.com/2014/07/pentester-lab-php-lfi-post-exploitation.html Notes: root@kali:~# nmap 10.0.0.12 Starting Nmap 7.40 ( https://nmap.org ) at 2017-05-30 12:23 EDT Nmap scan report for 10.0.0.12 Host is up (0.00035s latency). Not shown: 999 filtered ports PORT    STATE SERVICE 80/tcp open   http MAC Address: 08:00:27:1F:12:24 (Oracle VirtualBox virtual NIC) Nmap done: 1 IP address (1 host up) scanned in 5.31 seconds root@kali:~# Enumerating port 80 Run dirb root@kali:~# dirb http://10.0.0.12/ ----------------- DIRB v2.22 By The Dark Raver...

VM 5: Vulnix :

Walkthru: A. https://mrh4sh.github.io/vulnix-solution [SMTP and Finger enumeration, creating linux user with specific UID, root squashing, ssh pwd cracking using medusa & hydra, logging using ssh keys, updating /usr/sbin/exportfs] B. http://overflowsecurity.com/hacklab-vulnix/ [ same as above. create ssh keys for root and copied to victim to login as root w/o recovering pwd] C. https://www.rebootuser.com/?p=988[ local bash shell from nfs] B. https://www.vulnhub.com/?q=vulnix&sort=date-des&type=vm [list of solutions] D. https://www.rebootuser.com/?p=988 [User Enumeration #1 – SMTP, Finger; Entry Point including hydra, Putty(using rlogin service), nfs (showmount,mount) ] Notes: - As you can see the root user is the only account which is logged on the remote  host.Now that we have a specific username we can use it in order to obtain more information about this user with the command  finger root@host . -  Another effective use of the finger...

VM 13 : Basic Pentest 1 csec

Notes: Walkthru: 1. https://medium.com/@evire/basic-pentesting-1-7251fb3e3f9e [ w/metasploi t using Wordpress t] 2. https://prasannakumar.in/infosec/vulnhub-basic-pentesting-1-writeup/ [ w/metasploit using ftp ] 3.  https://www.ceos3c.com/hacking/basic-pentesting-1-walkthrough/ [ by uploading php-reverse-shell in wordpress ] 4. http://k3ramas.blogspot.com/2018/02/basic-pentesting-1-walkthrough.html [  access wordpress config file to get pwd and access the DB ] 5.  https://cowsayroot.com/walkthrough-basic-pentesting-1/ [ Wpscan, ftp metasploit vulnerability, phpbash ] 6.   http://www.hackingarticles.in/hack-the-basic-penetration-vm-boot2root-challenge/    [use msfvenom to create  to create php shell to be uploaded in Wordpress ] 7.   https://d7x.promiselabs.net/2018/01/30/ctf-basic-pentesting-a-guide-for-beginners/ [adding command using using PHP] Notes:  Ports - 21...ProFTPD 1.3.3c - 22 openSSH 7.2p2 ubuntu ...