LinuxQuestions.org
Visit Jeremy's Blog.
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 12-21-2010, 08:04 PM   #1
javaer
LQ Newbie
 
Registered: Dec 2010
Posts: 6

Rep: Reputation: 0
What does this command mean?


I am reading a tool manual and it instructs to use such a command:
Code:
cat word-list | sort +1 -rn | \ awk '{ print $1}' > result.txt
Especially, what does the 'sort' parameters and awk do?
Thanks for explanation.
 
Old 12-21-2010, 08:12 PM   #2
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Debian, Mageia, and whatever VMs I happen to be playing with
Posts: 11,690
Blog Entries: 12

Rep: Reputation: 2904Reputation: 2904Reputation: 2904Reputation: 2904Reputation: 2904Reputation: 2904Reputation: 2904Reputation: 2904Reputation: 2904Reputation: 2904Reputation: 2904
From this link:

Quote:
In the next example, the output of cat is piped to the sort filter in order to alphabetize the lines of text after concatenation and prior to writing to file4:

cat file1 file2 file3 | sort > file4
 
Old 12-21-2010, 08:13 PM   #3
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 650Reputation: 650Reputation: 650Reputation: 650Reputation: 650Reputation: 650
For any basic command there will be a man page ... 'man sort' 'man awk'

- sort: I'm not sure whether the '+1' is valid but -r = reverse and -n = numeric
- awk: $1 indicates it will print the first field

cheers
 
Old 12-21-2010, 08:24 PM   #4
javaer
LQ Newbie
 
Registered: Dec 2010
Posts: 6

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by kbp View Post
For any basic command there will be a man page ... 'man sort' 'man awk'

- sort: I'm not sure whether the '+1' is valid but -r = reverse and -n = numeric
- awk: $1 indicates it will print the first field

cheers
Yes, I can't make sense of the '+1' either. Also, what about the slash "\" before the command "awk"? What does it do?

The original command from the manual is here:
Code:
cat UNTAGGED-CORPUS | Utilities/wordlist-make.prl | sort +1 -rn | \
 awk '{ print $1}' > BIGWORDLIST
Any further idea? Thanks.
 
Old 12-21-2010, 08:29 PM   #5
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 650Reputation: 650Reputation: 650Reputation: 650Reputation: 650Reputation: 650
The '\' is interpreted as meaning "continue on the next line", it's used in textbooks and examples so you can copy/paste without having to worry about fixing up long lines.

The '+1' may be valid on other *nix's

Last edited by kbp; 12-21-2010 at 08:40 PM.
 
Old 12-21-2010, 08:45 PM   #6
javaer
LQ Newbie
 
Registered: Dec 2010
Posts: 6

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by kbp View Post
The '\' is interpreted as meaning "continue on the next line", it's used in textbooks and examples so you can copy/paste without having to worry about fixing up long lines.

The '+1' may be valid on other *nix's
So I should remove the slash '\' when I actually execute this command? Because anyway I can't get this command to work on my cygwin environment.
 
Old 12-21-2010, 09:14 PM   #7
javaer
LQ Newbie
 
Registered: Dec 2010
Posts: 6

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by kbp View Post
The '\' is interpreted as meaning "continue on the next line", it's used in textbooks and examples so you can copy/paste without having to worry about fixing up long lines.

The '+1' may be valid on other *nix's
I just found a tutorial:

"Sort on n+1 st field (old style key definition): sort +n"

So if the file has this format:
a 2
b 3
c 2
...

'sort +1' will sort the first column in that file?
 
Old 12-21-2010, 09:23 PM   #8
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 12,604
Blog Entries: 25

Rep: Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981
Hi,

Welcome to LQ!

Just a few links to aid you to gaining some understanding. Sure some may seem beyond a newbie but you must start somewhere;



Linux Documentation Project
Rute Tutorial & Exposition
Linux Command Guide
Utimate Linux Newbie Guide
LinuxSelfHelp
Getting Started with Linux
Bash Beginners Guide
Bash Reference Manual
Advanced Bash-Scripting Guide
Linux Home Networking



The above links and others can be found at 'Slackware-Links'. More than just SlackwareŽ links!
 
Old 12-21-2010, 10:05 PM   #9
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 650Reputation: 650Reputation: 650Reputation: 650Reputation: 650Reputation: 650
Quote:
So I should remove the slash '\' when I actually execute this command?
.. it doesn't matter, bash will understand that the next line is part of the same command or ignore it if you don't use more than one line. Try removing the '+1' and it should work ok

cheers
 
  


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
Batch file conversion command? the same command on all files in a folder ? pete2222 Linux - General 6 10-02-2010 12:59 PM
Bash Command Line Editor, while typing run another command before executing current? gumaheru Linux - General 5 04-13-2010 12:21 PM
how to copy drive using dd and tee command parallely? source code of dd command mdfakkeer Linux - Software 1 02-10-2010 02:31 PM
URGENT! Is there any command to get a history command lines and time in SUSE Linux.? igsoper Linux - Software 5 06-25-2009 03:14 AM
LXer: The Linux Command Shell For Beginners: Fear Not The Command Line! LXer Syndicated Linux News 0 12-22-2008 07:30 PM


All times are GMT -5. The time now is 06:57 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