0% found this document useful (0 votes)
75 views2 pages

1.awk General Syntax Is As Bellow.: 2.to Replace A Pattern in A File

This document provides examples of using various Linux commands and tools including: 1. The general syntax for awk scripts with BEGIN and END blocks to perform initializations and final actions. 2. Using awk with gsub to replace patterns in a file and print to a new destination file. 3. Using find to search for a filename in the current directory. 4. Using paste to concatenate two files side by side into an output file. 5. Using grep with -B to print lines before a matched pattern. 6. Using grep with -A to print lines after a matched pattern.

Uploaded by

Shankhadeep Das
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)
75 views2 pages

1.awk General Syntax Is As Bellow.: 2.to Replace A Pattern in A File

This document provides examples of using various Linux commands and tools including: 1. The general syntax for awk scripts with BEGIN and END blocks to perform initializations and final actions. 2. Using awk with gsub to replace patterns in a file and print to a new destination file. 3. Using find to search for a filename in the current directory. 4. Using paste to concatenate two files side by side into an output file. 5. Using grep with -B to print lines before a matched pattern. 6. Using grep with -A to print lines after a matched pattern.

Uploaded by

Shankhadeep Das
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/ 2

1.Awk general syntax is as bellow.

awk 'BEGIN
{<initializations>}
<search pattern 1> {<program actions>}
<search pattern 2> {<program actions>}
...
END
{<final actions>}'

2.To replace a pattern in a file.


awk '{gsub(/pattern to be replaced/,"pattern to be replaced with
");print}' filename>dest_filename.
Dest_filename will have made changes

3. searching a file in current directory


find . -name \*filename

4.concatinating 2 files side by side


paste a_file b_file > outfilename

5. printing n lines before a parrern is matched


grep -B 2 "important" online_backup.dat

6. printing n lines after a parrern is matched


grep -A 2 "flexibility" linux_enterpise.dat
7. awk '/SUMMARY/ {print $1}' daqa_report.xml
9.awk '{ sub(/candidate/, "& and his wife"); print }'
10.sed '/unix/ a "Add a new line"' file.txt (use \ for ")
add a line after match
11. sed '/unix/ i "Add a new line"' file.txt
add a line initial to match
12.while (($key,$value) = each(%$h2)) accessing hash
13. # Get command line options, variables should start with $opt<switch>

use Getopt::Long;
my $ret = &GetOptions('help',
\$opt_help,
'modelname=s', \$opt_modelname,
'm=s',
\$opt_modelname
);
14. exeption handle.
$SIG{'INT'} = \&exceptionhandler;
$SIG{'TERM'} = \&exceptionhandler;

1. 15. $string =~ s/^\s+//; #remove leading spaces


2. $string =~ s/\s+$//; #remove trailing spaces

15 .vimrc content
syn on
set nu
set wrap
16. deleting a line if a pattern is found in vi
:g/{pattern}/d
17: back substitution in vi
:%s/^\(.*\)$/RewriteRule ^\1 [R=301,L]/g

18. to do remove a line


perl -pi -e 'if(/acetate/){undef $_}' your_file

You might also like