LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-22-2014, 12:10 PM   #1
jundoerr
LQ Newbie
 
Registered: Apr 2014
Posts: 5

Rep: Reputation: Disabled
Question 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
 
Old 04-22-2014, 12:18 PM   #2
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 979
Blog Entries: 2

Rep: Reputation: 235Reputation: 235Reputation: 235
Look up each command you don't understand until you have covered the whole thing.
 
Old 04-22-2014, 12:37 PM   #3
jundoerr
LQ Newbie
 
Registered: Apr 2014
Posts: 5

Original Poster
Rep: Reputation: Disabled
I did, however, it does not make sense once you put them together
 
Old 04-22-2014, 12:47 PM   #4
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 3,774
Blog Entries: 1

Rep: Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339
What script? I just see a command.
 
Old 04-22-2014, 01:27 PM   #5
jundoerr
LQ Newbie
 
Registered: Apr 2014
Posts: 5

Original Poster
Rep: Reputation: Disabled
I saved this command to a exe file called scriptA, then run scriptA through a few text files to test the result. thanks, Jun
 
Old 04-22-2014, 01:37 PM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,245

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
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.
 
Old 04-22-2014, 01:49 PM   #7
jundoerr
LQ Newbie
 
Registered: Apr 2014
Posts: 5

Original Poster
Rep: Reputation: Disabled
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 ?
 
Old 04-22-2014, 02:02 PM   #8
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,245

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
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
 
Old 04-22-2014, 02:03 PM   #9
jundoerr
LQ Newbie
 
Registered: Apr 2014
Posts: 5

Original Poster
Rep: Reputation: Disabled
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
 
Old 04-22-2014, 02:25 PM   #10
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,245

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script/Perl Script to remove the string until it finds special character '_' pooppp Programming 10 07-17-2012 10:36 AM
Shell script/Perl Script to remove the string until it finds special character '_' pooppp Programming 1 07-13-2012 02:03 AM
Shell script, Perl script, command or utility to convert Binary to text Perseus Programming 26 07-12-2012 07:00 AM
[SOLVED] bash and xterm: how make apps started by and for a script persist when script terminates porphyry5 Linux - General 4 06-15-2011 02:27 PM
[SOLVED] Script question: create a shell script in kde to log in on a server with ssh c4719929 Linux - Newbie 1 01-31-2011 04:05 AM


All times are GMT -5. The time now is 02:43 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration