SHELL SCRIPTING PART 3 || CUT COMMANDS IN SHELL SCRIPT

                  CUT COMMANDS IN LINUX SHELL SCRIPTING


FOR PART 1 : CLICK HERE

FOR PART 2 : CLICK HERE


CUT #1

For each line of input, If you want to print its  character on a new line for a total of  lines of output.
We can do this using cut command in the following way.


Sample input :

HELLO 

WORLD

HOW ARE YOU


cut -c3

The Output will be as follows
l
r
w

CUT #2

To Display the  and  character from each line of text.


Sample Input

Hello

World

how are you


cut -c 2,7

If You are giving Input as a file , then the command will be :

cut -c 2,7 filename.txt

Then the output will be 

  • e
  • o
  • oe


CUT#3

Display a range of characters starting at the  position of a string and ending at the  position (both positions included).

SAMPLE INPUT:
  • Hello
  • World
  • how are you

cut -c2-7


Sample Output :
  • ello
  • orld
  • ow are


CUT #4

Display the first four characters from each line of text.


Sample Input

Hello
World
how are you
cut -c 1-4


Sample Output

Hell
Worl
how

Post a Comment

0 Comments