Programming :: Basename With Command Substitutions And Xargs

Jun 17, 2011

I get this behavior on Slackware 13.37, which includes BASH 4.1.010. Yes, BASH is my shell. I have a file called a.flac and I'm in the directory that contains it.

The output of the ls command is expected:
Code:
ls *.flac
gives:
Code:
a.flac

Removing the extension with basename works as expected:
Code:
basename a.flac .flac
gives:
Code:
a

Putting the above command in a variable substitution works as expected:
Code:
echo `basename a.flac .flac`
gives:
Code:
a

Using xargs with ls and a variable substitution works as expected:
Code:
ls *.flac | xargs -i echo `echo {}`
gives:
Code:
a.flac

However, when I try to add the basename command to the above command, it stops working.
Code:
ls *.flac | xargs -i echo `basename {} .flac`
gives:
Code:
a.flac

Whereas the result I expect is:
Code:
a
Why is it not working, and how do I make it work?

View 3 Replies


ADVERTISEMENT

Programming :: Using AWK Within Bash Command Via Xargs

Mar 24, 2011

I often want to extract some info using awk from a variable/filename while running other things using xargs and sh. Below is an example:
Code: ls -1 *.txt | xargs -i sh -c 'NEW=`echo $0 | awk -F'_' '{print $1}'`; echo $NEW' {}

In the above case I would like to grab just the first field from a filename (delimited by '_') from within an sh command. This is a simplified example, where normally I would be doing some further data processing with the sh command(s).

The error message that I get is:
Code: }`; echo $NEW: -c: line 0: unexpected EOF while looking for matching ``'
}`; echo $NEW: -c: line 1: syntax error: unexpected end of file.
I haven't been able to figure out how to escape the awk command properly.

View 1 Replies View Related

Programming :: Script To Insert Characters At End Of Basename In A Filename

Aug 19, 2010

Enterprise Linux 4 (2.6.9-78 kernel)...rename not working! Need to insert "_T" at the end of every file in a directory, just before the ".extension"

I have tried sed substitution with no success (because I do not know the codes and effects of anchoring well enough).

An example filename:

My failed tests:

Code:

Code:

Code:

Code:

View 9 Replies View Related

General :: Xargs - How Some Command Receive Input From Both Sides

Mar 9, 2010

I would like to ask the following:
1) ls -l |grep test -> this will grep every "ls -l" output line
2) ls -1 |xargs grep test -> this will grep every single file with test
3) ls -1 |xargs echo -> this will echo directory list
4) ls -1 |echo -> this does nothing!!!

My question is: how some command can receive input from "both sides" (grep can grep whole output or every single file - xargs, the same is for i.e. wc command). 4) echo does nothing (it's a single echo command).

View 1 Replies View Related

Programming :: Xargs With Output Of Find

Jul 15, 2011

I'm testing some multi-plat java code and I'm getting a bit frustrated with the Linux tests. I need to run the command:
Code:
$ java -jar /home/developer/TCO/TabletComicOptimizer.jar <file> <args[]>
against all the files that match a specific criteria. I've tried various find syntax and I can't seem to get it right.

Normally I would just create a bash script and populate the results of find into an array and then just enumerate the collection but in this specific case I want to demonstrate this operation at the bash terminal.

I've tried things like:
Code:
~/TCO $ find . -type f -iname "*.cb[rz]" | xargs java -jar TabletComicOptimizer.jar {} 1200x1800 ;
Thinking that the {} is the substitution for each file returned by find but it's not working. How do I execute my java program against each result in the find operation?

View 6 Replies View Related

Programming :: Using Sed With Variable Created Using Xargs / Unterminated Error

Jan 12, 2009

I have an awk program that finds all files of a specific filename and deletes them from selected subdirectories. There is logic in the awk to avoid certain subdirectories, and this is initialized via a parameter in the beginning statement of the awk. The parameter should have all of the subdirectory names at the top level. This varies from time to time, so I cannot hard-code the value.I'm having a problem initializing the awk parameter using sed. I'm setting a variable (named subdir) using an "ls" command piped to "xargs". I'm then trying to substitute that value into the awk using the sed command.

View 3 Replies View Related

General :: Page 2 - Get Basename Without Extension Not Working?

Mar 12, 2011

Quote:Originally Posted by SimonJM It almost smacks of your script being wrapped up in something elseGot it sorted, did the logic in PHP and linked directly to ffmpeg

View 2 Replies View Related

General :: Unable To Get Basename Of File Without Extension

Mar 4, 2011

Trying to get the basename of a file without the extension, I found this snippet but it just returns command not found twice:

[Code]....

Also tried (with and without the quotes on input and file_ext):

input=$1
file_ext=.${input##*.}
base=`basename "$input" $file_ext`

executed: convert.sh /path/music.wav But it echoes base as music.wav

View 14 Replies View Related

General :: Expanding Globs In Xargs?

Jun 29, 2011

I have a directory like this:
mkdir test
cd test
touch file{0,1}.txt otherfile{0,1}.txt stuff{0,1}.txt

I want to run some command such as ls on certain types of files in the directory and have the * (glob) expand to all possibilities for the filename.

echo 'file otherfile' | tr ' ' '
' | xargs -I % ls %*.txt

This command does not expand the glob and tries to look for the literal 'file*.txt'

How do I write a similar command that expands the globs? (I want to use xargs so the command can be run in parallel)

View 1 Replies View Related

General :: Copy Files Using Xargs From A Folder To Another?

Jun 10, 2009

I'm trying to copy a list of files except the files which has ".log" in the filename to another folder.I can run it correctly when I am located in the Source folder, but not when I am in any other location.cd /home/me/Sourcels /home/me/Source -1|grep -v "^.*log$" |xargs -n 1 -iHERE cp -r HERE /home/me/DestinationHow can I indicate both Source and Destination Folder?

View 2 Replies View Related

Fedora :: Using Xargs With Yum (Removing List Of Software)

Jan 23, 2010

I used the command shown below to remove a list of software using yum. It worked, but is there a way of doing this without using the -y option? I would like to review the results before the transaction takes place. I would like to use the same method for installing additional software after a clean install.
cat filename | xargs yum -y remove

View 8 Replies View Related

General :: Xargs CD Not Working (Echo Some Directory)

Mar 18, 2010

Please explain why
Code:
echo some_directory | xargs cd
is not working.
Code:
echo some_directory | xargs ls
is working as expected.

View 14 Replies View Related

General :: Xargs - Inserting Picture Into Group

Jun 17, 2011

I want to insert a picture into a group of pictures (I memorized their names in a text file) resulting a new group of picture (which I also memorized their name in another text file), but I have a problem doing that. I want to write something like that:

$> cat file1 | cat file2 | xargs composite -blend 30 text.jpg line_file1 line_file2
where
file1 is:
frame1.jpg
frame2.jpg
frame3.jpg
....

and file2 is:
new_frame1.jpg
new_frame2.jpg
new_frame3.jpg
...

View 4 Replies View Related

Server :: Backup One Liner Find Xargs CP

May 25, 2011

I will eventually script this but wanted to know where I screwed up when trying to get this oneliner to work. In a nutshell, I want to created a backup directory, find any files that have changed in the last 48hrs and them copy them to the newly made backup directory.

PHP Code:
date=$(date +%m%d%Y)mkdir -p /home/test_dir/backup$date;find . -mtime 1|xargs -0 cp -r -t /home/test_dir/backup$date

When I do this I get:
PHP Code:
a bunch of junk !#$#$$#! File name too long

I also tried:
PHP Code:
date=$(date +%m%d%Y)mkdir -p /home/test_dir/backup$date;find 
. -mtime 1|xargs -0 cp -r {} /home/test_dir/backup$date

View 7 Replies View Related

Software :: Find Xargs Shred Seems Really Slow

Nov 18, 2010

What am I doing wrong here ? Shredding a directory with files is incredibly slow. If I create a file of similar size it is around 1000 times faster. Filesystem is ext4, OS is Slack current. Looking at top it shows shred's status as 'D' which, according to the man page, means uninterruptible sleep ! Also /usr/bin/time shows around 10 minutes but that time was printed on stdout approx. 7 minutes before the command prompt reappeared !

Code:
[virgil@thunderbird2:~/q] $ du -sh
336M.
[virgil@thunderbird2:~/q] $ find . -type d | wc
160 160 12038
[virgil@thunderbird2:~/q] $ find . -type f | wc
6721 6721 687549
[virgil@thunderbird2:~/q] $ /usr/bin/time find . -type f -print0 | xargs -0 -r shred -zu
0.00user 0.00system 10:11.76elapsed 0%CPU (0avgtext+0avgdata 3616maxresident)k
0inputs+0outputs (0major+285minor)pagefaults 0swaps
[virgil@thunderbird2:~]

[virgil@thunderbird2:~] $ dd if=/dev/urandom of=qwerty bs=336M count=1
1+0 records in
1+0 records out
352321536 bytes (352 MB) copied, 51.6693 s, 6.8 MB/s
[virgil@thunderbird2:~]
[virgil@thunderbird2:~] $ ls -l qwerty
-rw-r--r-- 1 virgil virgil 352321536 2010-11-18 15:13 qwerty
[virgil@thunderbird2:~]
[virgil@thunderbird2:~] $ /usr/bin/time shred -zu qwerty
0.92user 0.78system 0:16.94elapsed 10%CPU (0avgtext+0avgdata 2912maxresident)k
0inputs+2752528outputs (0major+235minor)pagefaults 0swaps

View 3 Replies View Related

General :: Xargs And Unzip All Files To Specific Directory?

Jun 22, 2009

I'm trying to find all zip files timestamped from the past 7 days, then unzip them into a different director.I tried the following, but it only unzipped one of three files that meet the 7 day criteria. What am I missing?Code:find /home/user/public_html/zip_files/ -iname "*.zip" -mtime -7 -print0 | xargs -n10 unzip -LL -o -d /home/user/public_html/another_directory/

View 1 Replies View Related

General :: Traverse The File System And Rename (xargs Or Sed)?

May 15, 2011

I need your inputs on performing some operations:-

a. Traverse from top Level directory, find all the directories

b. Rename all these directories to <original name>.dir

c. Once the renaming is done - search from top level and retain only those directories which has .txt content in them.

d. Delete rest all.....

Can i use xargs here to perform operation a and b , or will sed will be useful.

View 14 Replies View Related

Programming :: Effect Of Using Eval To Execute A Command As Opposed To Writing It On The Command-line?

Jun 18, 2010

Code: cmd='date | wc'

$cmd If this script is executed, an error is generated. The reason written was that "The execution fails because the pipe is not expanded and is passed to date as an argument".What is meant by expansion of pipe. When we execute date | wc on the command line, it goes fine.then | is not treated as an argument. Why?

View 4 Replies View Related

Programming :: Command Line Invocation Of Gnome-terminal To Run More Than One Command?

Feb 16, 2010

I am trying to learn how to pass more than a one-command startup for gnome-terminal.

I will give an example of what I'm trying to do here:

Code:
#! /bin/bash
#
#TODO write this for gnome and xterm
USAGE="
${0##*/} [-x] [-g]
code....

However, running with the -g option to invoke gnome-terminal, I get a "There was an error creating the child process for this terminal" error.

This same error occurs if the gnome-terminal line is changed to

Code:
gnome-terminal -e mcTerm

Is there any way to pass more than one command on to gnome-terminal? I have tried various single and double quoting senarios and in a final attempt, I abstracted to an exported function all to no avail. Perhaps even though gnome-term is better at many things than xterm, xterm trumps it in this instance.

View 4 Replies View Related

Programming :: System Command / 'mcc' Is Not A Recognised As An Internal Or External Command?

Apr 13, 2010

I am writing a perl script which uses the matlab compiler to compile a .m file.

I am using the system("mcc �m file.m"). I have matlab installed and both script and exe are in the same drive.But i get the following error .

'mcc' is not a recognised as an internal or external command ,operable in program or batch file.

View 5 Replies View Related

Programming :: Show The Output Of Shell Command Into A Textbox, Ex Ps -efc Command?

Oct 20, 2010

I am using gtk to program GUI. How can I show the output of shell command into a textbox, ex ps -efc command ?

View 3 Replies View Related

Programming :: Convert This Awk Command From Command Line Into An Awk Script ?

Oct 15, 2010

I'm trying to convert this awk command from command line into an awk script, but just cannot get it to work:

This is what i have after my BEGIN

Am i missing something here? this just prints out the count for everyline, not counting lines on 5th field that match 'A'

View 1 Replies View Related

Programming :: Calling Command From History Using Variable Like !$command?

Nov 19, 2008

suppose i store the history number of a command say :

1004 cat file

Then now i want to run it like : !1004 but by using a variable.

command=1004
!$command

i am getting errors like :

command=1004command

View 2 Replies View Related

Programming :: Bash Ambiguous Redirect - Redirect One Command Output Which Will Be Treat As A Content Of File For Another Command?

Mar 9, 2011

I am trying to grep multiple numbers from file, grep does have the -f option for that.

Code: grep -f <`seq 500 520` /etc/passwd I know this could be done with

Code: for i in `seq 500 520`; do grep "$i" /etc/passwd; done But my question is fare more behind this example. It is possible to redirect one command output which will be treat as a content of file for another command ?

View 2 Replies View Related

Programming :: Command To Run Another One On Few Lines

Jul 23, 2010

Is there a command which can be used to run some other command on a few lines from a file or an o/p of some file. (the kind of role that -exec option does for the find command). (I have solved the purpose using a bash loop but would like to know if there exists a command).

View 4 Replies View Related

Programming :: Cp Command -f Is Not HAPPENING?

Mar 20, 2011

What's the deal with this bloody commandI trying to do an update of a product.The -f is suppose to "force" the overwrite of existing files isn't it?Well every time I run the command it keeps asking me to allow it to overwrite the files.. the programs is too long for me to sit here hitting the "y" and "enter key"

View 2 Replies View Related

Programming :: Use The Seq Command But Can't Get It To Work?

Mar 24, 2011

I have a script that will build a list of hosts and it works fine Code: for ((i=$START; i<=$END; i++)); do echo "$NAME$i"; done But I need it to build the START and END on different number formats (i.e. 1 -> 10, 01->10, 001 ->010)

I am trying to use the seq command but can't get it to work quite right with the -w flag in the following Code: for ((myseq=$START; myseq<=$END; myseq ++)) do echo "$NAME${myseq}" done I am fully aware that this syntax is probably wrong, and need to know how to correct it.

View 1 Replies View Related

Programming :: Add New Command In Minix?

Mar 12, 2011

Is anyone familiar with the Minix OS? i want to know what is the Process to add a new command in Minix that uses system call served by the memory manager server

View 1 Replies View Related

Programming :: Bash Command From PHP?

Jul 14, 2011

Distro: Centos 5, PHP 5I have done a bit research on running bash commands from php and there was little success. This is my relevant php script

<?php
echo exec('pwd');
?>

[code]...

View 16 Replies View Related

Programming :: Get The Getopts Command To Run?

May 12, 2010

im trying to get the getopts command to run but for some reason the -d option fails to populate the variable and it remains empty.

Code:
#!/bin/bash
usage()
{
cat << EOF
usage: $0 options

[Code].....

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved