Sponsored Content
Top Forums Shell Programming and Scripting awk & basename puzzler - advise sought Post 302732941 by Don Cragun on Monday 19th of November 2012 11:32:02 AM
Old 11-19-2012
Quote:
Originally Posted by davidra
Agma / Don

Many thanks for responding

I've tried both and I think the one that I more readily understand and has worked all OK is your contribution Don

Agma - apologies but didn't understand <source##*/>....the ##* bit but I did appreciate you taking the time to explain that I didn't need cat / while
Hi davidra,
I'm glad to hear that my contribution worked for you.

This is what ${source##*/} does: it looks at the shell variable named source and if its value matches the pattern */ (which matches any string that ends with a / character), it removes the longest match for that pattern from the start (left) of the string. If $source does not contain any / characters, it is expanded unchanged. Similarly, ${var#pattern} removes the shortest match for pattern from the start of the expansion of $var, ${var%pattern} removes the shortest match for pattern from the end of the expansion of $var, and ${var%%pattern} removes the longest match for pattern from the end of the expansion of $var. For example:
Code:
src="/usr/src/cmd.c"
echo X${src##*/}X X${src#*/}X X${src%/*}X X${src%%/*}X X${src%XYZ}X

produces the output:
Code:
Xcmd.cX Xusr/src/cmd.cX X/usr/srcX XX X/usr/src/cmd.cX

This User Gave Thanks to Don Cragun For This Post:
 

10 More Discussions You Might Find Interesting

1. What is on Your Mind?

Spammers: Advice being sought

The Web-based contact form on my site has been under distributed spamming attacks for nearly a month already. Obviously, a spammer has tried to generate HTTP requests containing ads to male drugs and all sorts of similar stuff directly to the form mail processor script on my site using a robot, as... (5 Replies)
Discussion started by: cbkihong
5 Replies

2. Shell Programming and Scripting

Using find command with awk or basename

Hi, I am using the following command to extract any log files that are older than 3 days using the following command. find DIR/LOGDIR -type f -mtime +3 |grep LOG > log_list.out The results are DIR/LOGDIR/1.LOG DIR/LOGDIR/2.LOG DIR/LOGDIR/3.LOG DIR/LOGDIR/4.LOG How do inculde (basename... (4 Replies)
Discussion started by: sam_78_nyc
4 Replies

3. Shell Programming and Scripting

getting basename inside awk script

hi if we have to use basename how can we do this in awk? did the below but is not working.. psg -t "?"| awk '{ command=($5 ~ /^/)? $9:$8 # cmd_name=`basename $command` (gives error) system("basename $command >>... (10 Replies)
Discussion started by: Anteus
10 Replies

4. Shell Programming and Scripting

scripting/awk help : awk sum output is not comming in regular format. Pls advise.

Hi Experts, I am adding a column of numbers with awk , however not getting correct output: # awk '{sum+=$1} END {print sum}' datafile 2.15291e+06 How can I getthe output like : 2152910 Thank you.. # awk '{sum+=$1} END {print sum}' datafile 2.15079e+06 (3 Replies)
Discussion started by: rveri
3 Replies

5. Shell Programming and Scripting

extracting basename in awk or nawk

I am having a hard time extracting the file name from the above code. Instead of printing /folder/file.1$.5$, I would like it to print the file name file.1$.5$. I have tried using basename but it looks like NAWK or AWK does not recognise basename. Each time I type it in, it prints out the word... (4 Replies)
Discussion started by: asemota
4 Replies

6. Shell Programming and Scripting

Need advise to process the file with awk

Hi gurus, i need your advise on how to process this file using awk. i have this file COLA COLB COLC COLD COLE COLF COLG COLH AAAA 86 111 122 133 144 155 266 377 BBBB 70 211 222 233 244 255 266 ... (6 Replies)
Discussion started by: ablanc
6 Replies

7. UNIX for Dummies Questions & Answers

awk and basename

im trying to extract the basename of a process running on a host processx is running at host1 as /applications/myapps/bin/processx i wanted to check if its running, then extract the basename only using: $ ssh host1 "ps aux | grep -v 'grep' | grep 'processx'" | awk '{ print basename $11}' ... (10 Replies)
Discussion started by: kaboink
10 Replies

8. Shell Programming and Scripting

korn shell script puzzler

Here is a very simple Korn shell script running on an AIX 5.3 box. Why does this work without the $ prepended to RET_CD? #!/bin/ksh RET_CD=0 if && then echo "RET_CD is not 0 and not 2" else echo "RET_CD is a 0 or a 2" fi (3 Replies)
Discussion started by: beldar
3 Replies

9. Shell Programming and Scripting

Solaris script using awk giving errors - please advise

I'm using solaris 10 Scenario as follows I have a logfile with 2 columns: column 1 = source directory + filename column 2 = destination directory + filename Using cron, my script polls for new files and adds them to the logfile ($ELOG) as described above. Using sed, the distination... (2 Replies)
Discussion started by: davidra
2 Replies

10. Shell Programming and Scripting

awk Help: quick and easy question may be: How to use &&

Hi Guru's. I am trying to use to check if $5 is greater than 80 & if not 100, then to print $0 : awk '{ if ($5>80) && if ($5 != 100) print $0} But getting error: >bdf1|sed 's/%//g'|awk '{ if ($5>80) && if ($5 != 100) print $0}' syntax error The source line is 1. The error... (6 Replies)
Discussion started by: rveri
6 Replies
GIT-SEND-PACK(1)						    Git Manual							  GIT-SEND-PACK(1)

NAME
git-send-pack - Push objects over Git protocol to another repository SYNOPSIS
git send-pack [--all] [--dry-run] [--force] [--receive-pack=<git-receive-pack>] [--verbose] [--thin] [<host>:]<directory> [<ref>...] DESCRIPTION
Usually you would want to use git push, which is a higher-level wrapper of this command, instead. See git-push(1). Invokes git-receive-pack on a possibly remote repository, and updates it from the current repository, sending named refs. OPTIONS
--receive-pack=<git-receive-pack> Path to the git-receive-pack program on the remote end. Sometimes useful when pushing to a remote repository over ssh, and you do not have the program in a directory on the default $PATH. --exec=<git-receive-pack> Same as --receive-pack=<git-receive-pack>. --all Instead of explicitly specifying which refs to update, update all heads that locally exist. --dry-run Do everything except actually send the updates. --force Usually, the command refuses to update a remote ref that is not an ancestor of the local ref used to overwrite it. This flag disables the check. What this means is that the remote repository can lose commits; use it with care. --verbose Run verbosely. --thin Send a "thin" pack, which records objects in deltified form based on objects not included in the pack to reduce network traffic. <host> A remote host to house the repository. When this part is specified, git-receive-pack is invoked via ssh. <directory> The repository to update. <ref>... The remote refs to update. SPECIFYING THE REFS
There are three ways to specify which refs to update on the remote end. With --all flag, all refs that exist locally are transferred to the remote side. You cannot specify any <ref> if you use this flag. Without --all and without any <ref>, the heads that exist both on the local side and on the remote side are updated. When one or more <ref> are specified explicitly, it can be either a single pattern, or a pair of such pattern separated by a colon ":" (this means that a ref name cannot have a colon in it). A single pattern <name> is just a shorthand for <name>:<name>. Each pattern pair consists of the source side (before the colon) and the destination side (after the colon). The ref to be pushed is determined by finding a match that matches the source side, and where it is pushed is determined by using the destination side. The rules used to match a ref are the same rules used by git rev-parse to resolve a symbolic ref name. See git-rev-parse(1). o It is an error if <src> does not match exactly one of the local refs. o It is an error if <dst> matches more than one remote refs. o If <dst> does not match any remote ref, either o it has to start with "refs/"; <dst> is used as the destination literally in this case. o <src> == <dst> and the ref that matched the <src> must not exist in the set of remote refs; the ref matched <src> locally is used as the name of the destination. Without --force, the <src> ref is stored at the remote only if <dst> does not exist, or <dst> is a proper subset (i.e. an ancestor) of <src>. This check, known as "fast-forward check", is performed in order to avoid accidentally overwriting the remote ref and lose other peoples' commits from there. With --force, the fast-forward check is disabled for all refs. Optionally, a <ref> parameter can be prefixed with a plus + sign to disable the fast-forward check only on that ref. GIT
Part of the git(1) suite Git 1.8.3.1 06/10/2014 GIT-SEND-PACK(1)
All times are GMT -4. The time now is 01:57 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy