HW3-CST383

HW3-CST383 - files should have unique names and have a...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
1. Write a sed script to number each line contained in a plain text file. sed 'N;s/\n/\. /' filename 2. Write a sed script to convert a DOS plain text file to a UNIX file. sed 's/.$//' filename 3. Write a sed script to remove leading and trailing whitespace from each line in a plain text file sed 's/^[ \t]*//' filename | sed 's/[ \t]*$//' 4. Write a sed script to center a text file in an 80 column width using a five space margin. 5. Write a sed script to remove duplicate consecutive lines from a plain text file. sed '$!N; /^\(.*\)\n\1$/!P; D' filename 6. Write an awk program to split large text files into smaller pieces the output
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: files should have unique names and have a default size of 500 lines per output files. awk 'BEGIN{RS="END";OFS="\n"} {$1=$1; print > "myfile"NR}' test.txt 7. Write an awk program to find and remove duplicate adjacent occurrences of the same word (ie: we often write "the the" or "had had"). awk '{ while(++i<=NF) printf (!a[$i]++) ? $i FS : ""; i=split("",a); print "" }' filename 8. Write an awk program to print out word usage counts in a plain text document. { for (i = 1; i <= NF; i++) freq[$i]++ } END { for (word in freq) printf "%s\t%d\n", word, freq[word] }...
View Full Document

This note was uploaded on 04/06/2010 for the course CST 383 taught by Professor Whitehouse during the Spring '10 term at Arizona.

Ask a homework question - tutors are online