0% found this document useful (0 votes)
16 views4 pages

Osy PR8

The document outlines practical exercises for text processing commands, including word, line, and character counting in a file named 'data.txt'. It discusses the applications of the paste command, cursor movement in text editors, options for the wc command, and various types of filters used in Linux. Additionally, it explains the significance of delimiters in the paste command and provides exercises for executing shell commands and capturing their results.

Uploaded by

daddyrx53
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views4 pages

Osy PR8

The document outlines practical exercises for text processing commands, including word, line, and character counting in a file named 'data.txt'. It discusses the applications of the paste command, cursor movement in text editors, options for the wc command, and various types of filters used in Linux. Additionally, it explains the significance of delimiters in the paste command and provides exercises for executing shell commands and capturing their results.

Uploaded by

daddyrx53
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

NAME: ROHAN SAWANT

ROLL. NO.: 22203B0017


BATCH 1

Practical no.: 8
AIM: Execute text processing commands.

Program Code:
Write the commands for:

1. Counting number of words in the ‘data.txt’


Command: wc -w data.txt

2. Counting number of lines in ‘data.txt’


Command: wc -l data.txt

3. Counting all Characters in the ‘data.txt’


Command: wc -m data.txt

Practical related Questions:


1. Give Applications of Paste Command.
a. Combine Files Horizontally: Merges lines from multiple files side by side. For
example, paste file1.txt file2.txt combines lines from both files into a single line per
output line.
b. Create Tabular Output: Useful for creating tabular data from multiple files or
commands. For example, combining a list of names with corresponding phone numbers.

c. Merge Data Streams: Combining the output of different commands, such as


command1 | paste - file2.txt, where - represents the standard input.

2. How to move cursor to end of a line.


a. In vi or vim: Press Shift + $ to move to the end of the line.

b. In nano: Press Ctrl + _ (underscore) then Ctrl + V and End to jump to the end of the line.

3. What are the options of wc command?


Options of the wc Command:
-l : Count the number of lines.

-w : Count the number of words.

-c : Count the number of bytes (characters).


NAME: ROHAN SAWANT
ROLL. NO.: 22203B0017
BATCH 1

-m : Count the number of characters (in multi-byte encodings).

4. What are different types of filters used in Linux?


Different Types of Filters Used in Linux:
Text Filters: grep (search text), sed (stream editor), awk (pattern scanning and processing).

Sorting Filters: sort (sort lines of text files).

Formatting Filters: fmt (simple text formatting), pr (prepare text files for printing).

Transformation Filters: tr (translate or delete characters), cut (remove sections from lines
of files).

5. What is difference between $cat abc and $cat|more (File abc shall consists of more
than 25 lines in it )

Command Description Behavior


$ cat abc Displays the entire Shows all lines of the file at once,
content of the file abc. which can quickly scroll past if
the file is long.
`$ cat abc more` Uses more to paginate the output
of cat.

Exercise:
1. Write the significance of following.
i. Only one character is specified
$ paste -d "" number state capital
1| Arunachal Pradesh|Itanagar
2|Assam|Dispur
3|Andra Pradesh| Hyderabad
4|Bihar|Patna
5|Chhattisgrah|Raipur

a. No Delimiter: By specifying an empty delimiter (-d ""), the output directly


concatenates the columns without adding any spaces or other characters between
them. This can be useful when you want to create a compact, delimited output without
any extra characters.
b. Concatenation: This approach concatenates data from different sources into a
single line for each row. This is useful when the format of the output needs to be
NAME: ROHAN SAWANT
ROLL. NO.: 22203B0017
BATCH 1

customized, and the absence of a delimiter can help in creating specific formats or
structures.
ii. More than one character is specified
$paste -d “|,” number state capital
1| Arunachal Pradesh,Itanagar
2|Assam,Dispur
3|Andra Pradesh,Hyderabad
4|Bihar,Patna
5|Chhattisgrah,Raipur

Significance:

 Cyclic Delimiter Usage: By specifying more than one delimiter, paste alternates
between the delimiters. In this case, | is used to separate the first column from the
second, and , is used to separate the second column from the third.
 Formatted Output: This approach allows for more complex formatting of the output.
For example, using | to separate different types of information and , to separate sub-
items can make the data easier to read or fit specific formatting requirements.
In the output:

 The | delimiter separates the number column from the state column.
 The , delimiter separates the state column from the capital column.
iii. -s (serial), Combination of -d and -s, -version (write its syntax and example)
1. Create a new file and practice executing shell commands from within the editor. Capture
the results of some shell commands into the file.
2. How to get help?
NAME: ROHAN SAWANT
ROLL. NO.: 22203B0017
BATCH 1

2. Try the commands and write output with its meaning


i. tr “[a-f]” “[0-5]” < employee (employee is name of file)

ii. tr -s “ “ <employee

iii. tr -d “f” < employee

You might also like