Regex and Functions

Go to Problems

Sed/Awk

Sed

Sed is a powerful text stream editor which can do insertion, deletion, search and replace.

Input:

cat
caat
caaat
caaaat
caaaaat
Replace consecutive multiple a with single a
sed 's/a\{2,\}/a/g' cats.txt

Output:

cat
cat
cat
cat
cat
Awk

Awk searches files for text containing a pattern and performs a specific action on that line/text.

Input:

A,20,30
B,10,5
C,25,40
D,40,10
Calculate total of the students
awk -F, 'BEGIN {printf "name \t sub1 \t sub2 \t total\n"} {printf "%s \t %s \t %s \t %s\n", $1, $2, $3,$2+$3}' marks.txt 

Output

name 	 sub1 	 sub2 	 total
A 20 30 50
B 10 5 15
C 25 40 65
D 40 10 50

Serious about Learning Scripting ?

Learn this and a lot more with Scaler Academy's industry vetted curriculum.
Shell scripting
Problem Score Companies Time Status
Swap Forward And Backward Slash 200
13:38
Sort by Frequency 250
30:24
Valid Email Address 350
29:08
Convert Integer To Roman Number 400
29:48