LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 06-14-2018, 04:03 PM   #1
ash997
LQ Newbie
 
Registered: Jun 2018
Posts: 14

Rep: Reputation: Disabled
Command help


If I have the following command grep ",9" and I want the output of that command to be in this command sort t "," k 2 how do I do that and do I need to have the file at just the end or at the end of both commands?
 
Old 06-14-2018, 04:12 PM   #2
coralfang
Member
 
Registered: Nov 2010
Location: Bristol, UK
Distribution: Slackware, FreeBSD
Posts: 711
Blog Entries: 3

Rep: Reputation: 212Reputation: 212Reputation: 212
Hi. You need to pipe the command to the next. You can do this with a "|" character. This sends the output of the previous command to the next one.

For example;
Code:
grep ",9" /path/to/my/file | sort -t "," -k 2
Have a look at this for a better explanation of pipes: https://www.guru99.com/linux-pipe-grep.html
 
Old 06-14-2018, 04:21 PM   #3
ash997
LQ Newbie
 
Registered: Jun 2018
Posts: 14

Original Poster
Rep: Reputation: Disabled
could you tell me what I am doing wrong on this command
sort –t "," –k1 -/jaunty/labdata | cut –d "," -f 2,3
 
Old 06-14-2018, 04:22 PM   #4
ash997
LQ Newbie
 
Registered: Jun 2018
Posts: 14

Original Poster
Rep: Reputation: Disabled
sort –t "," –k1 -/jaunty/labdata | cut –d "," -f 2,3
 
Old 06-14-2018, 04:23 PM   #5
ash997
LQ Newbie
 
Registered: Jun 2018
Posts: 14

Original Poster
Rep: Reputation: Disabled
could you tell me what I am doing wrong with this command
sort –t "," –k1 -/jaunty/labdata | cut –d "," -f 2,3
 
Old 06-14-2018, 04:28 PM   #6
coralfang
Member
 
Registered: Nov 2010
Location: Bristol, UK
Distribution: Slackware, FreeBSD
Posts: 711
Blog Entries: 3

Rep: Reputation: 212Reputation: 212Reputation: 212
It's hard to say unless you post an example of some entries that your file contains. What are you trying to do?

Edit;

With your command here;
Code:
sort –t "," –k1 -/jaunty/labdata | cut –d "," -f 2,3
You don't need to place a "-" before the filename, see "man sort";

Quote:
sort [OPTION]... [FILE]...
You probably want this:
Code:
sort –t "," –k1 /jaunty/labdata | cut –d "," -f 2,3

Last edited by coralfang; 06-14-2018 at 04:32 PM.
 
Old 06-14-2018, 04:46 PM   #7
ash997
LQ Newbie
 
Registered: Jun 2018
Posts: 14

Original Poster
Rep: Reputation: Disabled
Now this command what am I doing wrong

<file1 cut -d',' -f4 | sort -n | uniq -c
 
Old 06-14-2018, 05:18 PM   #8
coralfang
Member
 
Registered: Nov 2010
Location: Bristol, UK
Distribution: Slackware, FreeBSD
Posts: 711
Blog Entries: 3

Rep: Reputation: 212Reputation: 212Reputation: 212
You're redirecting "file1" to nowhere, so the other commands that are piped won't receive any input.
 
Old 06-15-2018, 02:43 PM   #9
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,380

Rep: Reputation: 979Reputation: 979Reputation: 979Reputation: 979Reputation: 979Reputation: 979Reputation: 979Reputation: 979
This is obviously homework.
 
Old 06-15-2018, 02:47 PM   #10
rtmistler
Moderator
 
Registered: Mar 2011
Location: MA, USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 7,074
Blog Entries: 12

Rep: Reputation: 2604Reputation: 2604Reputation: 2604Reputation: 2604Reputation: 2604Reputation: 2604Reputation: 2604Reputation: 2604Reputation: 2604Reputation: 2604Reputation: 2604
@ash997,

Review the LQ Site FAQ for information about how best to form your questions and how to give clear information to your fellow LQ members.

Brief, and very unclear updates are not helpful.
 
Old 06-16-2018, 05:57 AM   #11
MadeInGermany
Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 875

Rep: Reputation: 379Reputation: 379Reputation: 379Reputation: 379
Quote:
Originally Posted by coralfang View Post
You're redirecting "file1" to nowhere, so the other commands that are piped won't receive any input.
No!
The <file can be everywhere, even before the command! This is sometimes better readable, e.g. when a pipe follows.
The following 4 commands are equivalent, where the two middle commands look confusing, only added for educational reason.
Code:
<file command arg1 arg2
command <file arg1 arg2
command arg1 <file arg2
command arg1 arg2 <file
BTW only the zsh allows to consequently use
Code:
<file {
 read header
 echo "$header"
 sort
}
or
Code:
<file while read line
do
 ...
done
Other shells require the <file after the block
Code:
{
 read header
 echo "$header"
 sort
} <file

while read line
do
 ...
done <file

Last edited by MadeInGermany; 06-17-2018 at 02:26 AM.
 
Old 06-16-2018, 06:33 AM   #12
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 16,973

Rep: Reputation: 2564Reputation: 2564Reputation: 2564Reputation: 2564Reputation: 2564Reputation: 2564Reputation: 2564Reputation: 2564Reputation: 2564Reputation: 2564Reputation: 2564
It should be noted this later question is from another obviously homework thread. Supposedly from a course.
 
  


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
[SOLVED] [SOLVED] bash script: can echo command, command works if I type, but command doesn't work in script ... why? hopeless_n00b Linux - Newbie 10 07-12-2018 05:57 AM
ILO: Using Virtual Media with the Command-Line Interface command not working on ILO3 LittleMaster Linux - Server 0 10-31-2017 11:44 AM
Command/Script required to send an email alert in case command will not respond rajaniyer123 Linux - General 1 05-19-2012 01:12 PM
Executing shell command from JSP file with command line arg from URL orcusomega Programming 2 01-13-2012 03:38 PM
Bash Command Line Editor, while typing run another command before executing current? gumaheru Linux - General 5 04-13-2010 11:21 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:34 PM.

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