You are on page 1of 1

1.

Display the first and fifth columns of the password file with a tab between them
awk -F: '{print $1 "\t" $5}' /etc/passwd
2. replace first column as "ORACLE" in SOMEFILE
awk '{$1 = "ORACLE"; print }' SOMEFILE
3. sum the values in column 1
awk 'BEGIN{total=0;} {total += $1;} END{print "total is
", total}' SOMEFILE
4. Convert DOS newlines (CR/LF) to Unix format
sed 's/^M$//' < infile > outfile # in bash/tcsh, to get ^M press Ctrl-
V then Ctrl-M
5. Delete trailing whitespace (spaces, tabs) from end of each line
sed 's/[ \t]*$//' < infile > outfile
6. print the 4th, 3rd, and 2nd columns of SOMEFILE (in that order), and sort on the
last column (the 2nd column of the original file)
cat SOMEFILE | awk '{ print $4 " " $3 " " $2 }' | sort +2
7. list all files with a size less than 100 bytes
ls -l | awk '{if ($5 < 100) {print $5 " " $8}}'
8. In a file where each line begins with 'File' followed by one or more digits
followed by '=', e.g., 'File23=', find the duplicates
awk -F = '{print $2}' untitled.pls |sort|uniq -c |sort
9. delete the lines up to and including the regular expression (REGEX)

$ sed '1,/REGEX/d;' somefile.txt

You might also like