LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   what does this script do ? (https://www.linuxquestions.org/questions/linux-newbie-8/what-does-this-script-do-4175502582/)

jundoerr 04-22-2014 11:10 AM

what does this script do ?
 
I can break down this script in few pieces, but could not figure it out what is the purpose of this script ? Would someone please help me ? Maybe this script was a not good way to write a script ?

cat $1 | tr-sc "[A-Z]" "[a-z]" "[|012*]" |sort | uniq -c | sort -n | tail

I saved this script and run through a few text file, below are the results I got:

[root@QuickMPEP bin]# scriptA file1.txt
13 in
14 We
15 a
18 free
18 software
24 to
25 of
26 and
31 Fedora
31 the
[root@QuickMPEP bin]# scriptA file1.txt
13 in
14 We
15 a
18 free
18 software
24 to
25 of
26 and
31 Fedora
31 the
[root@QuickMPEP bin]# scriptA fileoutput
9 is
9 open
9 our
9 source
11 of
15 to
25 Hat
25 Red
27 the
31 and
[root@QuickMPEP bin]# scriptA redhat
20 for
20 on
29 cloud
32 Cloud
42 of
44 to
63 the
85 Red
86 Hat
88 and

linosaurusroot 04-22-2014 11:18 AM

Look up each command you don't understand until you have covered the whole thing.

jundoerr 04-22-2014 11:37 AM

I did, however, it does not make sense once you put them together :(

szboardstretcher 04-22-2014 11:47 AM

What script? I just see a command.

jundoerr 04-22-2014 12:27 PM

I saved this command to a exe file called scriptA, then run scriptA through a few text files to test the result. thanks, Jun

grail 04-22-2014 12:37 PM

Quote:

I did, however, it does not make sense once you put them together
Why not? If you have looked up each command and can successfully understand each part, how is the whole confusing?
You will need to explain further exactly which part of this command line example is confusing?

I would add, when displaying code / data please use [code][/code] tags so it is more readable.

jundoerr 04-22-2014 12:49 PM

I don't know about Linux at all, and I am learning now, I looked up the commends and took a guess:

cat $1 | tr-sc "[A-Z]" "[a-z]" "[|012*]" |sort | uniq -c | sort -n | tail

The first part code:
Code:

tr - sc "[A-Z]" "[a-z]" "[\012*]"
seems to be translate all upper case to lower case and start a new line, not sure what -sc means here ?

grail 04-22-2014 01:02 PM

Quote:

not sure what -sc means here
Check the man page.

When in doubt about any section, just rip it out and use it on a single / few lines and see what happens

jundoerr 04-22-2014 01:03 PM

Code:

sort | uniq -c|
it sort the file with prefix lines with number representing how many time they occurred

Code:

sort -n
compare according to string numerical value

Code:

tail
output the last part or tails of files.


not sure how to put together what this commend does : translate all the upper case to lowercase from the text file, and sort it according to the the string numerical value and start a new line , output the number of the occurrences ?

thanks, Jun

grail 04-22-2014 01:25 PM

Well I do find it interesting as the tr command errors for me, but as long as you got it to work :)


All times are GMT -5. The time now is 05:06 PM.