cleartool describe -ahlink -all filename - unix

I am doing a describe on a file:
ct desc -ahlink -all 5.txt
5.txt##/main/52
Hyperlinks:
Merge <- /vobs/TESTVOB/5.txt##/main/test_branch/1
Merge <- /vobs/TESTVOB/5.txt##/main/test_branch/2
Is there a way in clearcase using -fmt something to get the last hyperlink from the describe command without using unix commands to achieve it?
If not can someone suggest me the appropriate unix command to get the desired output?
I tried this command:
ct desc -ahlink -all 5.txt | grep Merge | cut -d "-" -f2
and this gives me:
/vobs/TESTVOB/5.txt##/main/test_branch/1
/vobs/TESTVOB/5.txt##/main/test_branch/2
I only want:
/vobs/TESTVOB/5.txt##/main/test_branch/2
Thanks in advance for your help

I don't know of a native way to get that last hyperlink.
So using a unix command like tail should be enough:
ct desc -ahlink -all 5.txt | grep Merge | tail -1 | cut -d "-" -f2

Related

grep multiple files get count of unique cut

I think I'm close on this, and saw similar questions but couldn't get it to work as I want. So, I have several log files and I would like to count the occurrences of several different service calls by date.
First I tried the below, the cut is just to get the first element (date) and 11th element (name of service call), which is specific to my log file:
grep -E "invoking webservice" *.log* | cut -d ' ' -f1 -f11 | sort | uniq -c
But this returned something that looks like:
5 log_1.log:2017-12-05 getLegs()
10 log_1.log:2017-12-05 getArms()
7 log_2.log:2017-12-05 getLegs()
13 log_2.log:2017-12-04 getLegs()
What I really want is:
12 2017-12-05 getLegs()
10 2017-12-05 getArms()
13 2017-12-04 getLegs()
I've seen examples where they cat * first, but looks like the same problem.
cat * | grep -E "invoking webservice" *.log* | cut -d ' ' -f1 -f11 | sort | uniq -c
What am I doing wrong? As always, thanks a lot!
Your issue seems to be that grep prefixes the matched lines with the filenames. (grep has this behavior when multiple filenames are specified, to disambiguate the results.) You can pass the -h to grep to not print the filenames:
grep -h "invoking webservice" *.log | cut -d ' ' -f1 -f11 | sort | uniq -c
Note that I dropped the -E flag, because it is used to enable extended regex support, and your example doesn't need it.
Alternatively, you could use cat to dump the content of files to standard output, and pipe that to grep. That would work, because it removes the need for filename parameters for grep:
cat *.log | grep "invoking webservice" | cut -d ' ' -f1 -f11 | sort | uniq -c

sort -t $'\t' equivalent compatible with POSIX sh?

I am trying use a for loop for multiple files in my directory with a pipe command,but it does not seem to work. When am running the same command on a single file it seems to work. Where am I getting it wrong?
for x in *summary-FDR0.05 ; do sort -t $'\t' -k8,8rn $x | head -n 50000 | sortBed -i > sorted_top_50k_$x.bed; done
All my files end with summary-FDR0.05. When I run
sort -t $'\t' -k8,8rn sample13-summary-FDR0.05 | head -n 50000 | sortBed -i > sorted_top_50k_S_13_O1_122*K27ac.bed
This seems to work well. May I know where I am getting it worng
Error:
sort: multi-character tab `$\\t'
Thanks
For POSIX compatibility, replace $'\t' with "$(printf "\t")".

Customizing print output after getting a column using 'cut' command

I'm trying to print the first column of output in a "customized" way, after executing a program that prints out a table. I know how to get the first column from the output, but I want to print each row between single quotes. So, right now I have the commands that can get me the first column:
./genTable | cut -f2 | xargs -0
What can I add to this command so that it prints the values between quotes. For example, the output right now looks like
apple
cider
vinegar
I want it to look like
'apple'
'cider'
'vinegar'
I'd use Perl. ./genTable | perl -nwla -e 'print \'$F[1]\''
I'd use awk ;-) , i.e.
./genTable | awk -v singleQ="'" '{print singleQ $1 singleQ}'
And of course you if you want super-minimalist, change all references from singleQ to Q ;-)
output
'apple'
'cider'
'vinegar'
IHTH

How to get a list of file names in different lines

I want to get a list of all the files in a directory, like with ls, so that each filename will be on a seperate line, without the extra details supplied by ls -l. I looked at ls --help and didn't find a solution. I tried doing
ls -l | cut --fields=9 -d" "
but ls doesn't use a fixed number of spaces between columns. Any idea on how to do this, preferably in one line?
ls -1
That is a number, not small L.
ls -1. From the help:
-1 list one file per line
Works on cygwin and FreeBSD, so it's probably not too GNU-specific.
solution without pipe-ing :-)
ls --format single-column
Note that the long options are only supported on the GNU coreutils where BSD ls only supports the short arguments -1
Perhaps:
ls | awk '{print $NF}'
ls | cat
...
or possibly, ls -1
Use sed command to list single columns
ls -l | sed 's/\(^[^0-9].\*[0-9]\*:[0-9]\*\) \(.*\)/\2/'
Try this:
$ ls | xargs -n num
Here num is number of columns you want to list in.
first you can use this. it will display the one file per line.
ls -l | sed 's/(.* )(.*)$/\2/'
or else you can use thus
find . -maxdepth 1 | sed 's/.///'
both the things are the same.
This is also working: echo -e "\n$(ls)"
This will also do
ls -l | awk '{print $NF}'

Using lsof to get a list of file names

EDIT 1
I'm having problems using the arguments given. Maybe it is the way I'm passing my arguments through NSTask? Any suggestions as to how I can do this?
NSTask *file_Task = [NSTask new];
[file_Task setLaunchPath:#"/usr/sbin/lsof"];
[file_Task setArguments:[NSArray arrayWithObjects:#"+p", the_Pid, nil]];
Good Afternoon Fellow Coders....
I'm using the following command:
lsof +p 13812
to get the list of a files accessed by a process. The thing is it is giving me a lot of additional information that I don't want such as TYPE, DEVICE, etc.
Is there an argument that I can add to the above command so that I get ONLY the NAME?
Thank you, thank you thank you! :)
Eric
You can use:
lsof -Fn +p 12345
This will output a list of lines, with the first being p followed by the process ID,
and all following lines consisting of n followed by the file name.
If you'd like to quickly preprocess this, you can do something similar to the following:
lsof -Fn +p 12345 | tail -n +2 | cut -c2-
See the lsof man page for more information, specifically under the OUTPUT FOR OTHER PROGRAMS heading.
try:
lsof | tr -s ' ' | cut -d' ' -f9
lsof +p 9174 | awk '{ print $9 }'
Listing the currently playing song (nfs file, accessed by user mpd):
$ sudo lsof -N -a -u mpd -Fn |
sed '/n/!d; s/^n//'
/R/audio/[...] Jay-Jay Johanson , So Tell The Girls That I Am Back.mp3
The sed part deletes any lines not starting with n and removes n in the final output.

Resources