Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I trust and completly believe that there are many Unix Gurus on this forum and I am just beginner ! hoping to reach there soon
I need small help.
Code:
[user01@centos-flash rel-01]$find . -type f -print |xargs p4 have|awk 'not on {print $1}'
./hf_rel-01.0.14073_cca.sql - file(s) not on client.
./hf_rel-01.0.29.14656_ccr.sql.commit - file(s) not on client.
./hf_rel-01.0.28_ccr.sql - file(s) not on client.
./hf_rel-01.0.27_ccr.sql - file(s) not on client.
./hf_rel-01.0.29.14074_cca.sql.commit - file(s) not on client.
./hf_rel-01.0.29.14191_ccr.sql - file(s) not on client.
./hf_rel-01.0.29.14085_ccr.sql - file(s) not on client.
./hf_rel-01.0.29.12459_ccr.sh - file(s) not on client.
./hf_rel-01.0.12_cca.sql - file(s) not on client.
./hf_rel-01.0.29.12701_ccr.sql - file(s) not on client.
./hf_rel-01.0.29.14013_cca.sql.commit - file(s) not on client.
./14074_CCCB2PRD_20110514.out - file(s) not on client.
./hf_rel-01.0.12_cca.sh - file(s) not on client.
./hf_rel-01.0.29.14180_ccr.sql.commit - file(s) not on client.
I need to extract only name of file say hf_rel-01.0.14073_cca.sql so on and so forth..
I even did
Code:
find . -type f -print |xargs p4 have|awk 'not on {print $1}'|grep -v "not on client"
You've chosen a certain solution for your problem and are stuck with that, could you explain what it is you are trying to accomplish?
Quote:
Originally Posted by sysmicuser
$ find . -type f -print | xargs p4 have | awk 'not on {print $1}'
You seem to be looking for normal files in the current and subdirectories (the find . -type f -print part), the rest of the pipe (xargs and the awk part) doesn't make any sense.
Please tell us what your starting point is and what you want as end-result. Depending on what it is you want to accomplish the find command might not be needed at all.
If I focus on the output of this part find . -type f -print |xargs p4 have, which I believe could produce lines like this ./hf_rel-01.0.14073_cca.sql - file(s) not on client. (of which you only want to print the filename) I would do something like this:
Code:
$ find . -type f -print | xargs p4 have | awk -F"[ /]" '/not on client/ { print $2 }'
The bold part looks for lines that contain not on client and will print the filename. You can use multiple field separators in awk (the -F"[ /]" part), in this case a space and the forward slash are the field separators.
Hope this helps.
Last edited by druuna; 03-17-2012 at 04:20 AM.
Reason: typo: filed -> field
[user01@centos-flash rel-01]$find . -type f -print | xargs p4 have | awk -F"[ /]" '/not on client/ { print $2 }'
./hf_rel-01.0.14073_cca.sql - file(s) not on client.
./hf_rel-01.0.29.14656_ccr.sql.commit - file(s) not on client.
./hf_rel-01.0.28_ccr.sql - file(s) not on client.
./hf_rel-01.0.27_ccr.sql - file(s) not on client.
./hf_rel-01.0.29.14074_cca.sql.commit - file(s) not on client.
./hf_rel-01.0.29.14191_ccr.sql - file(s) not on client.
./hf_rel-01.0.29.14085_ccr.sql - file(s) not on client.
./hf_rel-01.0.29.12459_ccr.sh - file(s) not on client.
./hf_rel-01.0.12_cca.sql - file(s) not on client.
I can only assume that the output generated by p4 have might have something to do with it. It might not print the output to the stdout (and or stderr).
Without knowing how the p4 program/script works and how it generates output this will be hard to trouble-shoot.
Does the following work? (please post output of commands, within code tags):
Code:
$ find . -type f -print | xargs p4 have > outfile
$ head -3 outfile
$ file outfile
$ od -c outfile | head
BTW: You are working on a linux box and are using bash as shell?
[user01@centos-flash 1.9.0.4.6.1]$find . -type f -print | xargs p4 have > outfile
./hf_1.9.0.4.6.1.0.14073_cca.sql - file(s) not on client.
./hf_1.9.0.4.6.1.0.29.14656_ccr.sql.commit - file(s) not on client.
./hf_1.9.0.4.6.1.0.28_ccr.sql - file(s) not on client.
./hf_1.9.0.4.6.1.0.27_ccr.sql - file(s) not on client.
./hf_1.9.0.4.6.1.0.29.14074_cca.sql.commit - file(s) not on client.
./hf_1.9.0.4.6.1.0.29.14191_ccr.sql - file(s) not on client.
./hf_1.9.0.4.6.1.0.29.14085_ccr.sql - file(s) not on client.
./hf_1.9.0.4.6.1.0.29.12459_ccr.sh - file(s) not on client.
./hf_1.9.0.4.6.1.0.12_cca.sql - file(s) not on client.
./hf_1.9.0.4.6.1.0.29.12701_ccr.sql - file(s) not on client.
./hf_1.9.0.4.6.1.0.29.14013_cca.sql.commit - file(s) not on client.
[code]
[user01@centos-flash 1.9.0.4.6.1]$file outfile
outfile: ASCII text
[user01@centos-flash 1.9.0.4.6.1]$
[code]
Output of command 4
Quote:
od -c outfile | head
Code:
[user01@centos-flash 1.9.0.4.6.1]$od -c outfile | head
0000000 / / g l i d e / m a i n / s c m
0000020 / h f s c r i p t s / 1 . 9 . 0
0000040 . 4 . 6 . 1 / h f _ 1 . 9 . 0 .
0000060 4 . 6 . 1 . 0 . 2 4 _ i n t . s
0000100 h # 1 - / a p p / s c m / p
0000120 4 w s / s c m b u i l d / s c m
0000140 t o o l s / h f s c r i p t s /
0000160 1 . 9 . 0 . 4 . 6 . 1 / h f _ 1
0000200 . 9 . 0 . 4 . 6 . 1 . 0 . 2 4 _
0000220 i n t . s h \n / / g l i d e / m
[user01@centos-flash 1.9.0.4.6.1]$
---------- Post added 03-17-12 at 11:30 PM ----------
Interesting to note that output and logfile are completely different !
The output you see in post #1 and post #5 are not send to stdout by the p4 program. The output from command 1 and 2 show this (outfile is filled with other information).
Without knowing what p4 does I cannot help you. It (p4) probably manipulates file descriptors for its multiple output.
I would suggest changing p4 so that the output that is now send to screen (the ./hf_1.9.0.4.6.1.0.14073_cca.sql - file(s) not on client. lines) are send to a seperate file, which you can then use.
Well I would like to ask you the most idiot question anyone would have ever asked. Sorry about my incompetent shell/unix skills
what is stdout and stderr
When any error is thrown does it means stderr and general output as stdout? what is exactly difference between them? how does unix os in intself what is error and what is output.
The reason I ask is whenever we do deployments I always capture any command out to a logfile by following command
2>&1 | tee -a <log_file>
does this means whatever is displayed on screen/terminal throw that stuff in <log_file> if thats the case it even throws build failed error in logfile should it not only throw stdout?
By default stdout (1) is used for normal output and stderr (2) is used for outputting error related messages. Both, by default, print their messages to screen.
A user or a script/program can manipulate this. If you use 2>&1 you tell bash to redirect the stderr (the 2) messages to stdout (the 1). Messages from both are now going through the same pipe.
Expanding on that: Why would you need/want that? When using this 2>&1 | tee -a <log_file>, redirecting to one pipe is needed because the tee command only captures stdout (man tee). If you would omit the 2>&1 part, normal output would be send to <log_file> and errors would go to the screen (stderr's default).
In the case of p4 I suspect one or more extra file descriptors ("pipes") to be created/used, which send output to screen (stderr and stdout are used for other output).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.