I'm trying to cd to a location I get from pkgutil.
cd $(pkgutil --files com.company.pkg | grep company | sed 's/\company.aaxplugin.*//g'| uniq | sed -e 's/ /\\ /g')
The output of
pkgutil --files com.company.pkg
is
Library
Library/Application Support
Library/Application Support/Avid
Library/Application Support/Avid/Audio
Library/Application Support/Avid/Audio/Plug-Ins
Library/Application Support/Avid/Audio/Plug-Ins/company.aaxplugin
Library/Application Support/Avid/Audio/Plug-Ins/company.aaxplugin/Contents
...
I use grep, sed and unique to get to:
Library/Application Support/Avid/Audio/Plug-Ins
Now I can't figure out a way to cd to that directory.. I tried putting quotes around the path, storing it in a variable, replacing " " with "\ " etc..
Any tips?
Thanks a lot!
I can't test the exact commands you have because I don't have those packages installed, but I was simulating output with spaces and got it to work.
$ cd "$(echo /Library/Application Support)"
was able to take me to the /Library/Application Support/ directory in both bash and zsh.
Thus, in your case, you'd want to surround the entire $(...) with ".
cd "$(pkgutil --files com.company.pkg | grep company | sed 's/\company.aaxplugin.*//g'| uniq | sed -e 's/ /\\ /g')"
Thanks a lot Piccolo!
Apparently I put the " in the wrong spot.
Related
I'm trying to organise and rename some roms I got, I've already used command line to remove regions like " (USA)" and " (Japan)" including the space in front from filenames. Now I need to update my .cue files, I've tried the following but something is missing...
grep --include={*.cue} -rnl './' -e " (USA)" | xargs -i# sed -i 's/ (USA)//g' #
grep --include={*.cue} -rnl './' -e " (Europe)" | xargs -i# sed -i 's/ (Europe)//g' #
grep --include={*.cue} -rnl './' -e " (Japan)" | xargs -i# sed -i 's/ (Japan)//g' #
I got it to work on one occasion but can't see to get it right again...
Awesome thanks, I used:
sed -i 's/ (Japan)//g;s/ (Europe)//g;s/ (USA)//g' *.cue
I have a folder containing about 2000 sub-folders, some containing even more sub-folders and some with files. I've used this code via Terminal:
cd /path/to/folder
ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^/]*//--/g' -e 's/^/ /' -e 's/-/|/'
to return a very nice recursive list of all the sub-folders but it does not list the files within those folders. Does anyone know how to amend this code so it produces the recursive folder list and includes the files?
For reasons that aren't worth getting into I'm limited to using Terminal on this computer and can't try a different method using C# or Java. Any help is appreciated.
How about using find like this:
find $PWD
Or using this alias:
alias stree='ls -R | grep : | sed -e '\''s/:$//'\'' -e '\''s/[^-][^\/]*\//--/g'\'' -e '\''s/^/ /'\'' -e '\''s/-/|/'\'''
I have search string in one variable ($AUD_DATE) and replace string in another variable ($YEST_DATE). I need to search file name in a folder using $AUD_DATE and then replace it with $YEST_DATE.
I tried using this link to do it but its not working with variables.
Find and replace filename recursively in a directory
shrivn1 $ AUD_DATE=140101
shrivn1 $ YEST_DATE=140124
shrivn1 $ ls *$AUD_DATE*
NULRL.PREM.DATA.CLRSFIFG.140101.dat NULRL.PREM.DATA.CLRTVEH.140101.dat
shrivn1 $ ls *$AUD_DATE*.dat | awk '{a=$1; gsub("$AUD_DATE","$YEST_DATE");printf "mv \"%s\" \"%s\"\n", a, $1}'
mv "NULRL.PREM.DATA.CLRSFIFG.140101.dat" "NULRL.PREM.DATA.CLRSFIFG.140101.dat"
mv "NULRL.PREM.DATA.CLRTVEH.140101.dat" "NULRL.PREM.DATA.CLRTVEH.140101.dat"
Actual output I need is
mv "NULRL.PREM.DATA.CLRSFIFG.140101.dat" "NULRL.PREM.DATA.CLRSFIFG.140124.dat"
mv "NULRL.PREM.DATA.CLRTVEH.140101.dat" "NULRL.PREM.DATA.CLRTVEH.140124.dat"
Thanks in advance
Approach 1
I generally create mv commands using sed and then pipe the output to sh. This approach allows me to see the commands that will be executed beforehand.
For example:
$ AUD_DATE=140101
$ YEST_DATE=140124
$ ls -1tr | grep "${AUD_DATE}" | sed "s/\(.*\)/mv \1 \1_${YEST_DATE}"
Once you are happpy with the output of the previous command;repeat it and pipe it's output to sh, like so:
$ ls -1tr | grep "${AUD_DATE}" | sed "s/\(.*\)/mv \1 \1_${YEST_DATE}" | sh
Approach 2
You could use xargs command.
ls -1tr | grep ${AUD_DATE}" | xargs -I target_file mv target_file target_file${YEST_DATE}
I have tried this command,
grep '/static' dir/* | xargs sed -i 's/\/static//g'
but the version of sed I am using does not support the -i argument.
To replace a string in a file, to the same input file as the output, I normally do this:
sed 's/\/static//g' filename.txt > new_filename.txt ; mv new_filename.txt filename.txt
OS X's version of sed does support -i, but it requires an argument to tell it what file extension to use for the backup file (or "" for no backup). BTW, you want grep -l to get just the filenames.
grep -l '/static' dir/* | xargs sed -i "" 's/\/static//g'
Use perl:
$ perl -pi.bak -e 's#/static##g' dir/*
You can do this using a loop:
for file in $(grep -l '/static' dir/*) ; do
sed 's/\/static//g' $file > $file.$$ && mv $file.$$ $file
done
I use the .$$ suffix ($$ is the process id of the current shell) to avoid collisions with existing file names, and && rather than ; to avoid clobbering the input file if the sed command fails for some reason. I also added -l so grep prints file names rather than matching lines.
Or you can install GNU sed (I'm not sure exactly how to do that on OSX).
How do I make a tree of all things with bash? What is the command?
tree /
or
find /
Update: #OP, since you have so much trouble with it, how about this alternative. On ubuntu 9.10, you should have bash 4.0 ? so try this
#!/bin/bash
shopt -s globstar
for rdir in /*/
do
for file in $rdir/**
do
echo "$file"
done
done
you should probably alias this :)
ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
(Warning: huge output)
$ find . -print | sed -e 's;/*/;|;g;s;|; |;g'
Add alias to ~/.bash_profile
alias tree="find . -print | sed -e 's;/*/;|;g;s;|; |;g'"
tree -R /
and then cry because it's enormous.
On a related note, to stop the command, press CTRL+C
Assuming you want to find something from tree, do
tree / > tree.txt
Then Ctrl + F it.