You are on page 1of 3

ses:-6

o sed command continue

-e -> to rxecute chain of sed command


N -> peocess multiple line

example:-
how to give new line after using sed command
'G'
1.
$ sed 'G' sed_example1.txt
who is he unix session unix session unix session

who is teaching unix session

front front end verification the of the of

what is the of odt

what is the of odt

2.
$ sed -e 'G' -e 'G' sed_example1.txt
who is he unix session unix session unix session

who is teaching unix session

front front end verification the of the of

what is the of odt

what is the of odt

3.
$ sed 'G;G' sed_example1.txt
who is he unix session unix session unix session

who is teaching unix session

front front end verification the of the of

what is the of odt

what is the of odt

4.
multiple line processeing
'N'
example:-
$ sed 'N;G;G' sed_example1.txt
who is he unix session unix session unix session
who is teaching unix session

front front end verification the of the of


what is the of odt

what is the of odt

$ sed 'N;N;G;G' sed_example1.txt


who is he unix session unix session unix session
who is teaching unix session
front front end verification the of the of

what is the of odt


what is the of odt

o awk
database

$1 -> 1st word of the line


$2 -> 2nd word of the line
...
$0 -> refers to entire line
$NF->the last word of the line
${NF-1} -> last but one word

NR ->number of rows

awk '{}' filename.ext

example:-
$ ls -ltrh | awk '{print
"permissions_given="$1"\tfile/directory_name=>"$NF}'
permissions_given=total file/directory_name=>33K
permissions_given=-rwxrwx---+
file/directory_name=>ses_2.txt
permissions_given=-rwxrwx---+
file/directory_name=>ses_3.txt
permissions_given=-rwxrwx---+
file/directory_name=>ses_4.txt
permissions_given=-rwxrwx---+
file/directory_name=>ses_5.txt
permissions_given=-rwxrwx---+
file/directory_name=>ses_!.txt
permissions_given=-rw-rw-r--+
file/directory_name=>sed_example2.txt
permissions_given=-rw-rw-r--+
file/directory_name=>sed_example4.txt
permissions_given=-rw-rw-r--+
file/directory_name=>sed_example3.txt
permissions_given=drwxrwxr-x+ file/directory_name=>demo2
permissions_given=-rw-rw-r--+ file/directory_name=>d
permissions_given=-rw-rw-r--+
file/directory_name=>sed_example1.txt
example:-
provide line number to file

awk '{print NR"\t"$0}' ses_4.txt |&tee ses_4.txt


awk '{print NR"\t"$0}' ses_4.txt > ses_4_num.txt

example:-

syntx :-
for(i=1;i<=100;i=i+1)

user_add_1 passwd_1
user_add_2 passwd_2
........
........
user_add_100 passwd_100

example:-
awk '{for(i=1;i<=100;i=i+1) print "user_add_"i"\tpasswd_"i }'
awk 'BEGIN {for(i=1;i<=100;i=i+1) print "user_add_"i"\tpasswd_"i }' >
user_add_info.txt

o passwd:-
change the passwd of user

$ passwd
Old password:
New password:
Re-enter new password:
Password changed.

o redirecting (>)
take the output of the previous command and redirects it to a new file
it donot update the exiting file

You might also like