LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 03-18-2015, 06:59 PM   #1
AcousticBruce
LQ Newbie
 
Registered: Mar 2015
Posts: 4

Rep: Reputation: Disabled
How to run a command in another command?


I am not sure how to ask this, sorry.

if I had a code like this

Code:
# grep -a ": " md5list.txt | cut -f2,3 -d

How can I run the command basename for each line of the output?

basename {(grep -a ": " md5list.txt | cut -f2,3 -d )}


EDIT: A little more clarity on what im doing:
I didn't realize that 'md5sums' was a link to a nice formatted page. So I copied all packages here and put them into a text file. I decided to write a script that put all of these in that format.

So basically, even though I have already ran the md5sum -c 'md5sum-list' I still want to finish this small project because I am learning a ton.

Last edited by AcousticBruce; 03-19-2015 at 06:59 AM.
 
Old 03-18-2015, 07:17 PM   #2
Philip Lacroix
Member
 
Registered: Jun 2012
Distribution: Slackware, *BSD
Posts: 396

Rep: Reputation: 470Reputation: 470Reputation: 470Reputation: 470Reputation: 470
Hi

This should work:

Code:
for filename in "$( grep -a ": " md5list.txt | cut -f2,3 -d " " )" ; do basename "$filename" ; done
<edit> In your example option "-d" has no argument: that will not work.

Philip

Last edited by Philip Lacroix; 03-18-2015 at 09:00 PM. Reason: added -d " " as clarified in #3
 
Old 03-18-2015, 07:46 PM   #3
AcousticBruce
LQ Newbie
 
Registered: Mar 2015
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Philip Lacroix View Post
Hi

This should work:

Code:
for filename in "$( grep -a ": " md5list.txt | cut -f2,3 )" ; do basename "$filename" ; done
<edit> In your example option "-d" has no argument: that will not work.

Philip
Actually, the -d had " " as an argument. Its hard to see though.

This is similar to your code but using {} instead of $()...

Code:
 for i in {1..5}; do echo $i; done
The code ran but stopped on the second output. There is 79 to go. Not sure why it stopped.



What about eval?? Would my code need that? I do not understand $() in your example. what does this do? what is it called?
Code:
for i in $(eval echo "{$START..$END}")

Last edited by AcousticBruce; 03-18-2015 at 07:52 PM.
 
Old 03-18-2015, 08:02 PM   #4
AcousticBruce
LQ Newbie
 
Registered: Mar 2015
Posts: 4

Original Poster
Rep: Reputation: Disabled
I worked with your code and came up with a way to iterate through the file, but still I can not figure how to run baseline.

Code:
# for i in {1..200}; do sed '$i,0!d' md5list.txt | grep -a ": "; done
How can I run baseline for each of these iterations?
 
Old 03-18-2015, 08:32 PM   #5
Philip Lacroix
Member
 
Registered: Jun 2012
Distribution: Slackware, *BSD
Posts: 396

Rep: Reputation: 470Reputation: 470Reputation: 470Reputation: 470Reputation: 470
Quote:
This is similar to your code but using {} instead of $()...
They have a completely different meaning, being similar only graphically. In one case you run the for loop for each line which is grepped and cut from your file: basename is run on the resulting string. This is called command substitution. Your example, on the other hand, uses extended brace expansion.

Quote:
The code ran but stopped on the second output. There is 79 to go. Not sure why it stopped.
Any error messages? Make sure that grep is actually capturing what you want, and that cut is actually finding something in the specified fields. Posting here a few lines from your file (or from a similar one with the same structure) may be helpful.

Quote:
What about eval?
Not sure if it is useful here.

This is a great reference guide for bash scripting: Advanced Bash-Scripting Guide

Last edited by Philip Lacroix; 03-18-2015 at 08:34 PM.
 
Old 03-18-2015, 08:51 PM   #6
Miati
Member
 
Registered: Dec 2014
Distribution: Linux Mint 17.*
Posts: 326

Rep: Reputation: 106Reputation: 106
Wish I knew what the md5list.txt file contained. Hard to help when that's not available. I am assuming it's the normal output of md5sum.

This may be a better method:

Code:
while read i
  do
    basename "$(echo "$i" | grep -a ": " | cut -f2,3 -d" ")"
done < md5list.txt
Each line of output is run through the while loop until done.
I added a " " to the -d cause I wasn't sure what you were defining so I figured whitespace.
 
Old 03-19-2015, 06:58 AM   #7
AcousticBruce
LQ Newbie
 
Registered: Mar 2015
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Miati View Post
Wish I knew what the md5list.txt file contained. Hard to help when that's not available. I am assuming it's the normal output of md5sum.

This may be a better method:

Code:
while read i
  do
    basename "$(echo "$i" | grep -a ": " | cut -f2,3 -d" ")"
done < md5list.txt
Each line of output is run through the while loop until done.
I added a " " to the -d cause I wasn't sure what you were defining so I figured whitespace.

Yes, whitespace is correct. Because I was using the PDF document, I didn't realize that 'md5sums' was a link to a nice formatted page. So I copied all packages and md5 text here and put them into a text file. I decided to write a script that put all of these in that format.

So basically, even though I have already ran the md5sum -c 'md5sum-list' I still want to finish this small project because I am learning a ton.

I ran your script and got a syntax error near unexpected token 'done'
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] run ps|grep command by script/command line ... ERROR: Unsupported option (BSD syntax) masuch Programming 4 05-23-2012 05:13 AM
Bash Command Line Editor, while typing run another command before executing current? gumaheru Linux - General 5 04-13-2010 12:21 PM
Is command line invocation of gnome-terminal to run more than one command possible? narnie Programming 4 02-17-2010 11:39 PM
Shell: command not found / Runs fine with "Run command" badbunny Linux - Newbie 1 01-22-2007 02:21 AM
Command to run another command against a list of files psweetma Linux - General 3 11-09-2005 06:29 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration