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

Info icon This 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
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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern