Archive for July, 2015

Quick SED walkthrough by example

July 26, 2015 Leave a comment

## This example is very useful in working with XML files

sed “/group/,/\/group/s/name/groupname/g” directory.xml

## search between the words “group” and “/group” and substitute “name” with “groupname” globally in file “directory.xml”, output to stdout; file not updated

sed -i “/group/,/\/group/s/name/groupname/g” directory.xml
## -i will update the file with the changes

Categories: Linux, Redhat

Awk notes

July 25, 2015 Leave a comment

Here’s a useful snippit/shell script that can tell you quite a bit on the power of awk:

awk -F”:” ‘ ‘
print “=============================================”
printf “%-8s %-3s %-3s %-15s %-15s\n”,”User”,”UID”,”GID”,”HOME”,”SHELL”
print “=============================================”
NR==1,NR==10( printf “%-8s %3d %3d %-15s %-15s\n”,$1,$3,$4,$6,$7 ) ‘ /etc/passwd
### End of script

BEGIN = Header info
%-8s = max width of field/string to pring (8s), left justified (-)
NR==1,NR==10 = Rows between 1-10
%3d = minimum 3 digits to print, right justified

Categories: Linux, Redhat