The script that displays the file information is used to help you better understand the file content. the script aims to display the content of the file, A few more rows are summarized. 01 #! /Bin/sh0203 # showfile. sh -- display the... of a file... the script that displays the file information is used to help you better understand the file content. the script aims to display the content of the file, A few more rows are summarized. 01 #! /Bin/sh02 03 # showfile. sh -- displays the content of a file, also include useful additional information 04 05 width = 7206 07for input08do09 lines = "$ (wc-l <$ input | sed's // g ') "10 chars =" $ (wc-c <$ input | sed's // g ') "11 owner =" $ (ls-ld $ input | awk '{print $3}') "12 echo" ---------------------------------------------------- "13 echo" File $ input ($ lines, $ chars characters, owned by $ owner): "14 echo "--------------------------------------- ------------------- "15 while read line16 do17 if [$ {# line}-gt" $ width "]; then18 echo" $ line "| fmt. sh | sed-e '1s/^ // '-E' 2, $ s/^/+/'19 else20 echo "$ line" 21 fi22 done <$ input23 echo "done" 24 done | more25 26 exit 0 script function, as you can see, there are some more visualized descriptions, showing the number of rows and characters. When the content of each line is displayed, a maximum of 72 characters are displayed. if there are more than 72 characters, multiple lines are truncated. The most difficult part in this script is to show the following: 1 echo "$ line" | fmt. sh | sed-e '1s/^ // '-E' 2, $ s/^/+/' it calls 14th scripts fmt. sh is used to format the output. The last MPs queue is used to add a space at the first letter of the first line in the sed expression; the second sed expression adds a plus sign and a space to the first letter of each line from row 2nd to the last line. test this script: 01 $ showfile ragged.txt using File ragged.txt (7 lines, 639 characters, owned by taylor): used So she sat on, with closed eyes, and half believed herself in06 Wonderland, though she knew she had but to open them again, and07 all wocould change to dull reality -- the grass wocould be only rustling08 + in the wind, and the pool rippling to the waving of the reeds -- the09 rattling teacups wocould change to tinkling sheep-bells, and the10 Queen's shrill cries to the voice of the shepherd boy -- and the11 sneeze12 of the baby, the shriek of the Gryphon, and all the other queer13 + noises, wocould change (she knew) to the confused clamor of the busy14 + farm-yard -- while the lowing of the cattle in the distance would15 + take the place of the Mock Turtle's heavy sobs.16 seconds -----------------------------------------------------------------
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.