LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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-22-2017, 10:40 AM   #1
ektoren
LQ Newbie
 
Registered: Jun 2017
Posts: 16

Rep: Reputation: Disabled
if you could help with this


I have stuck on symbols in a sentence and there is an argument my answers and my "friends" there was a discussion.I want to opened my mind because i confusing if something is right or wrong.I wrote cases with a,b,c etc.I want to tell me which one is right and which one is wrong because i have lost the sense and why it isnt.I with my friends are doing this and we have different results.Example a) is right , b) isnt right because...There are traps on those and i would be greatful if you could help with this.I have analize it much this issue but not sure because there was conflicts.Thanks a lot i appreciate if you could help. a)
Code:
 cat file2.txt > A | B
b)
Code:
 B 2> file3.txt | A >file1.txt 2> file2.txt
c)
Code:
A 2< file1.txt d) A | B | C <file3.txt
e)
Code:
A < file1.txt ; B < file2.txt
f)
Code:
A<file2.txt| while read x < file1.txt; do echo x "x is $x"; done

Last edited by ektoren; 06-22-2017 at 10:48 AM.
 
Old 06-22-2017, 10:45 AM   #2
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 9,952

Rep: Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148
you really need to learn how to use code blocks and format that better because that is hard to read.
Code:
cat file2.txt > A | B b) B 2> file3.txt | A >file1.txt 2> file2.txt c) A 2< file1.txt d) A | B | C <file3.txt e) A < file1.txt ; B < file2.txt f) A<file2.txt| while read x < file1.txt; do echo x "x is $x"; done
tell your friend(teacher) .. never mind.

| <-- that is called a pipe it directs output of one program into the input of another program.
> and >> are called redirection it takes standard input and output (IO) and E(rror) and redirects it to wherever you tell it to go.
Quote:
0 - stdin
1 - stdout
2 - stderr
or strings and redirects it into a file
Code:
echo "this is a string" > fileName
which is standard output and redirects it into a file.

Last edited by BW-userx; 06-22-2017 at 11:58 AM.
 
Old 06-22-2017, 10:49 AM   #3
ektoren
LQ Newbie
 
Registered: Jun 2017
Posts: 16

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by BW-userx View Post
you really need to learn how to use code blocks and format that better because that is hard to read.
Code:
cat file2.txt > A | B b) B 2> file3.txt | A >file1.txt 2> file2.txt c) A 2< file1.txt d) A | B | C <file3.txt e) A < file1.txt ; B < file2.txt f) A<file2.txt| while read x < file1.txt; do echo x "x is $x"; done
tell your friend(teacher) .. never mind.

| <-- that is called a pipe it directs output of one program into another
> and >> are called redirection it takes stdout and redirects it to wherever you tell it to go.
its ok now?Yes thanks but it has syntax error or not all of the above i wrote?which are right which wrong

Last edited by ektoren; 06-22-2017 at 10:51 AM.
 
Old 06-22-2017, 11:12 AM   #4
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 9,952

Rep: Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148
Quote:
Originally Posted by ektoren View Post
its ok now?Yes thanks but it has syntax error or not all of the above i wrote?which are right which wrong
OK i updated page I can see it now.

I'm gathering that you are wanting to know which code works and which does not.

Here, let me try to teach you how to take that information and put it to the test so you can learn how to rely on your own self judgments.

first off you'll have to create a test file or files with data inside of it using the same naming conventions as your questions. then using your command line in a terminal just run the code and check for the results.

I'll use a file already created. Because for the first one it has to have information inside if to even do anything. else you'll get empty files.
Code:
yahoo.com
75.126.162.205
google.com
http://www.linuxquestions.org
linuxquestions.org
Results A
Code:
userx%slackwhere ⚡ testingmefiles ⚡>  cat info.txt > A | B                                                        
bash: B: command not found
userx%slackwhere ⚡ testingmefiles ⚡>
Results B
Code:
userx%slackwhere ⚡ testingmefiles ⚡>  B 2> file3.txt | A >file1.txt 2> file2.txt
userx%slackwhere ⚡ testingmefiles ⚡> ls
A  file1.txt  file2.txt  file3.txt
userx%slackwhere ⚡ testingmefiles ⚡> cat A
yahoo.com
75.126.162.205
google.com
http://www.linuxquestions.org
linuxquestions.org
userx%slackwhere ⚡ testingmefiles ⚡> cat file1.txt
userx%slackwhere ⚡ testingmefiles ⚡> cat file2.txt
bash: A: command not found
userx%slackwhere ⚡ testingmefiles ⚡> cat file3.txt
bash: B: command not found
userx%slackwhere ⚡ testingmefiles ⚡>
Results C
Code:
userx%slackwhere ⚡ testingmefiles ⚡> A 2< file1.txt d) A | B | C <file3.txt
bash: syntax error near unexpected token `)'

userx%slackwhere ⚡ testingmefiles ⚡> ls
A  file1.txt  file2.txt  file3.txt
userx%slackwhere ⚡ testingmefiles ⚡>
Results E
Code:
userx%slackwhere ⚡ testingmefiles ⚡> A < file1.txt ; B < file2.txt
bash: A: command not found
bash: B: command not found
userx%slackwhere ⚡ testingmefiles ⚡>
Results F
Code:
userx%slackwhere ⚡ testingmefiles ⚡> A<file2.txt| while read x < file1.txt; do echo x "x is $x"; done
bash: A: command not found
userx%slackwhere ⚡ testingmefiles ⚡>
now you can determine what works and what does not. You just need to figure out why?

Last edited by BW-userx; 06-22-2017 at 11:18 AM.
 
Old 06-22-2017, 11:15 AM   #5
ektoren
LQ Newbie
 
Registered: Jun 2017
Posts: 16

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by BW-userx View Post
OK i updated page I can see it now.

I'm gathering that you are wanting to know which code works and which does not.

Here, let me try to teach you how to take that information and put it to the test so you can learn how to rely on your own self judgments.

first off you'll have to create a test file or files with data inside of it using the same naming conventions as your questions. then using your command line in a terminal just run the code and check for the results.

I'll use a file already created. Because for the first one it has to have information inside if to even do anything. else you'll get empty files.
Code:
yahoo.com
75.126.162.205
google.com
http://www.linuxquestions.org
linuxquestions.org
Results A
Code:
userx%slackwhere ⚡ testingmefiles ⚡>  cat info.txt > A | B                                                        
bash: B: command not found
userx%slackwhere ⚡ testingmefiles ⚡>
Results B
Code:
userx%slackwhere ⚡ testingmefiles ⚡>  B 2> file3.txt | A >file1.txt 2> file2.txt
userx%slackwhere ⚡ testingmefiles ⚡> ls
A  file1.txt  file2.txt  file3.txt  info.txt
userx%slackwhere ⚡ testingmefiles ⚡> cat file3.txt
bash: B: command not found
userx%slackwhere ⚡ testingmefiles ⚡> cat file2.txt
bash: A: command not found
userx%slackwhere ⚡ testingmefiles ⚡> cat file1.txt
userx%slackwhere ⚡ testingmefiles ⚡>
Results C
Code:
userx%slackwhere ⚡ testingmefiles ⚡> A 2< file1.txt d) A | B | C <file3.txt
bash: syntax error near unexpected token `)'
userx%slackwhere ⚡ testingmefiles ⚡>
Results E
Code:
userx%slackwhere ⚡ testingmefiles ⚡> A < file1.txt ; B < file2.txt
bash: A: command not found
bash: B: command not found
userx%slackwhere ⚡ testingmefiles ⚡>
Results F
Code:
userx%slackwhere ⚡ testingmefiles ⚡> A<file2.txt| while read x < file1.txt; do echo x "x is $x"; done
bash: A: command not found
userx%slackwhere ⚡ testingmefiles ⚡>
now you can determine what works and what does not. You just need to figure out why?
results b?
 
Old 06-22-2017, 11:24 AM   #6
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 9,952

Rep: Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148
Quote:
Originally Posted by ektoren View Post
results b?
what is b doing in that code? Can you explain what it is doing to me so I know you know what it is doing?

the code is
Code:
 B 2> file3.txt | A >file1.txt 2> file2.txt
 
Old 06-22-2017, 11:30 AM   #7
ektoren
LQ Newbie
 
Registered: Jun 2017
Posts: 16

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by BW-userx View Post
what is b doing in that code? Can you explain what it is doing to me so I know you know what it is doing?

the code is
Code:
 B 2> file3.txt | A >file1.txt 2> file2.txt
it shows the output but next it shows mistake
 
Old 06-22-2017, 11:33 AM   #8
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 9,952

Rep: Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148
1. seeing the set up on testing this code has not been fully established A and B maybe valid files. if not then which one actually throws the error, and not a message?

Unless as I think it is that C is a type O and because if you look at your questions you are missing that d -- you go from c to e and d is actually within c.

soooo that means.

Last edited by BW-userx; 06-22-2017 at 11:35 AM.
 
Old 06-22-2017, 11:46 AM   #9
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 9,952

Rep: Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148
A is wrong because of this
Code:
cat file2.txt > A | B
the piping is wrong if B is not a command that is why you get the return message.
Code:
userx%slackwhere ⚡ testingmefiles ⚡>  cat file2.txt > A | B
bash: B: command not found
B is wrong because there is no 'B' to work off of
Code:
 B 2> file3.txt | A >file1.txt 2> file2.txt
But it too could be right because.
B 2> file3.txt
that is redirecting stderr of B which is not present into file3.txt
then pipes that into the next command which is
A>file1.txt which gets nothing because it is bogus code so it returns a stderr that gets sent to file2.txt


etc...
mod:
D)
Code:
A | B | C <file3.txt
this does what?

is there an A
is there an B
is there an C
is there a file3.txt
what does the pipes do
and what does the 'backwards' redirection do with file3.txt if there is such a file?

for pipes and redirection go back and look at post #2

Last edited by BW-userx; 06-22-2017 at 11:58 AM.
 
Old 06-22-2017, 12:02 PM   #10
michaelk
Moderator
 
Registered: Aug 2002
Posts: 21,483

Rep: Reputation: 4091Reputation: 4091Reputation: 4091Reputation: 4091Reputation: 4091Reputation: 4091Reputation: 4091Reputation: 4091Reputation: 4091Reputation: 4091Reputation: 4091
Is this homework? Who says a) is right and b) isn't right?

Code:
a) cat file2.txt > A | B
To get you going for question a), A is a hypothetical file and B is a hypothetical program/script. As stated > redirects all output of the cat command which is the contents file2.txt into file A. If all output is redirected to a file then nothing can be piped to program B. From your previous text file
B = grep linuxquestions.org
Code:
cat info.txt | grep linuxquestions.org
Will output linuxquestions.org However
Code:
cat info.txt > file1.txt | grep linuxquestions.org
Outputs nothing since the output of the cat command is redirected to file1.txt. There is nothing wrong with the syntax except you might not see the desired output.

Can you explain question b)? Do you understand the difference between stdout and stderr?

Last edited by michaelk; 06-22-2017 at 12:33 PM. Reason: added example
 
  


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



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

All times are GMT -5. The time now is 04:51 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
Open Source Consulting | Domain Registration