LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   What does this command mean? (https://www.linuxquestions.org/questions/linux-newbie-8/what-does-this-command-mean-851678/)

javaer 12-21-2010 07:04 PM

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.

frankbell 12-21-2010 07:12 PM

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

kbp 12-21-2010 07:13 PM

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

javaer 12-21-2010 07:24 PM

Quote:

Originally Posted by kbp (Post 4199423)
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.

kbp 12-21-2010 07:29 PM

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

javaer 12-21-2010 07:45 PM

Quote:

Originally Posted by kbp (Post 4199439)
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.

javaer 12-21-2010 08:14 PM

Quote:

Originally Posted by kbp (Post 4199439)
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?

onebuck 12-21-2010 08:23 PM

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!

kbp 12-21-2010 09:05 PM

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


All times are GMT -5. The time now is 07:49 PM.