1 a 21
2 b 12
3 c 7
4 d 1
5 e 12
6 f 12.6
7 g 1.2
find a and replace by z
perl -pe 's/a/z/' input.txt (print on console)
perl -pi -e 's/a/z/g' input.txt (update input.txt)
1 z 21
2 b 12
3 c 7
4 d 1
5 e 12
6 f 12.6
7 g 1.2
print lines if contains 'a'
perl -ne 'print if /a/' input.txt
1 a 21
if col 1 = 2 replace col 1 by 2000
perl -lape 'if ($F[0] eq "2" ) { s/$F[0]/2000/;}' input.txt
1 a 21
2000 b 12
3 c 7
4 d 1
5 e 12
6 f 12.6
7 g 1.2
if col 1 = 2 or col 3 = 1 then replace col 2 by 2000
perl -lape 'if ($F[0] eq "2" || $F[2] eq "1") { s/$F[1]/2000/;}' input.txt
1 a 21
2 2000 12
3 c 7
4 2000 1
5 e 12
6 f 12.6
7 g 1.2
perl -apF\\t -e '$_="$F[1]\t$F[2]"' input.txt
a 21
b 12
c 7
d 1
e 12
f 12.6
g 1.2
perl -ne 'print if $. % 2' input.txt
1 a 21
3 c 7
5 e 12
7 g 1.2
# Print all unique lines
perl -ne 'print unless $a{$_}++' input.txt
# Print all lines from line 17 to line 30
perl -ne 'print if $. >= 17 && $. <= 30'
1 a 21
2 b 12
3 c 7
4 d 1
5 e 12
6 f 12.6
7 g 1.2
2 x 15
awk '{print > "Line"$1".txt"}' input.txt
ls *Line*
Line1.txt Line2.txt Line3.txt Line4.txt Line5.txt Line6.txt Line7.txt
head Line1.txt
1 a 21
head Line2.txt
2 b 12
2 x 15
perl -lane 'print if $F[0] eq 2' input.txt
awk '$1==2' input.txt
2 b 12
2 x 15
No comments:
Post a Comment