I want to run the basename command on a certain awk field.   echo "1 /this/is/a/path" | awk '{print $1" "system("/usr/bin/basename " $2)}'   but the output always produces a 0 from the system command. How do I print the real output?
10724
Here is my script (to find the files that contain a specified pattern):  find . -type f \     -exec awk -v vawk="$1" '/'"$vawk"'/ {c++} c&gt;0 { print ARGV[1]; exit 0 } END { if (! c) {exit 1}}' \{\} \;   I would like to use my script with an argument §:  MyScript.sh pattern   My problem is that I don't manage to put the $1 variable in awk.  When I try to debug my script  bash -x MyScript.sh pattern   Here is the output :  + find . -type f -exec awk -v vawk=pattern '// {c++} c&gt;0 {print ARGV[1] ; exit 0 } END { if (! c) {exit 1}}' '{}' ';'   The $vawk variable seems to be empty.  Any idea?
78635
How to store output command in a variable and use this variable again for next command after pipe?  lsblk | awk {'print $1'} | grep ^sd | parted $input mklable gpt mkpart primary "1 -1" -s   $input is output lsblk | awk {'print $1'} | grep ^sd command and use $input again in parted command.
8110
echo -e 'one two three\nfour five six\nseven eight nine' one two three four five six seven eight nine   how can I do some "MAGIC" do get this output?:  three six nine   UPDATE: I don't need it in this specific way, I need a general solution so that no matter how many columns are in a row, e.g.: awk always displays the last column.
91295
Why doesn't echo $1 print $1 in this simple bash script?    #!/bin/bash # function.sh print_something () { echo $1 } print_something  $ ./function.sh 123  -&gt; why doesn't it print '123' as a result?
111476
I am trying to write a bash shell function that will allow me to remove duplicate copies of directories from my PATH environment variable.   I was told that it is possible to achieve this with a one line command using the awk command, but I cannot figure out how to do it. Anybody know how?
46414
As per my knowledge, to determine the current shell we use echo $0 in the shell. Rather I want my script to check in which shell it is running. So, I tried to print $0 in the script and it returns the name of the script as it should. So, my question is how can I find which shell is my script running in during runtime?
61729
How can I write this with an AIX script correctly?  My requirement is to write this command in test.txt:  clock=$(prtconf -s | awk '{print $4,$5}')   I tried this command:  print 'clock=$(prtconf -s | awk '{print $4,$5}')' &gt; test.txt   Output written in test.txt gives me:  clock=$(prtconf -s | awk {print ,})   If I use " " quotes:  print "clock=$(prtconf -s | awk '{print $4,$5}')"   It gives me directly to:  clock=3612 MHz   How can I solve this?
47782
I am trying out the command  $ b=5; echo `$b`; -bash: 5: command not found   but it does not print 5 as it is supposed to. What am I missing here?   seems to say that ` evaluates the commands within and replaces them with the output.
122578
the following syntax print the output1 down   echo "$status"    output1:      component_name : TEZ_CLIENT     recovery_enabled : true     component_name : WEBHCAT_SERVER         recovery_enabled : true     component_name : YARN_CLIENT            recovery_enabled : true     component_name : ZKFC           recovery_enabled : true     component_name : ZOOKEEPER_CLIENT             recovery_enabled : true     component_name : ZOOKEEPER_SERVER                      recovery_enabled : true   how to add the printf syntax in order to get the following lines:  expected output      component_name : TEZ_CLIENT             recovery_enabled : true     component_name : WEBHCAT_SERVER         recovery_enabled : true     component_name : YARN_CLIENT            recovery_enabled : true     component_name : ZKFC                   recovery_enabled : true     component_name : ZOOKEEPER_CLIENT       recovery_enabled : true     component_name : ZOOKEEPER_SERVER       recovery_enabled : true
35975
The variable BUILDNUMBER is set to value 230. I expect 230_ to be printed for the command echo $BUILDNUMBER_ but the output is empty as shown below.  # echo $BUILDNUMBER_  # echo $BUILDNUMBER 230
27936
I've a command that outputs data to stdout (command1 -p=aaa -v=bbb -i=4). The output line can have the following value:  rate (10%) - name: value - 10Kbps   I want to grep that output in order to store that 'rate' (I guess pipe will be useful here). And finally, I would like that rate to be a value of a parameter on a second command (let's say command2 -t=${rate})  It looks to be tricky on my side; I would like to know better how to use pipes, grep, sed and so on.  I've tried lots of combinations like that one but I'm getting confused of these:  $ command1 -p=aaa -v=bbb -i=4 | grep "rate" 2&gt;&amp;1 command2 -t="rate was "${rate}
112122
Can anybody explain to me what the shell does in the two examples A) and B) below? It obviously behaves differently, but I can't find out why the output is different.  Example: Let's have a script in our current directory named bla.sh with only one command: echo ${0##/*} hello  A) Started as: ./bla.sh gives: ./bla.sh hello  B) Started as: . bla.sh gives: -bash hello  Since I use this in a script, the second output (because of the "-" in front of the -bash) kills the command. Of course, a simple -- before the ${...} helped, but I would love to understand what causes the output in the first place.I love bash. And vi[m]. But I digress…
17891
How do I execute the following shell command using the Python  module?  echo "input data" | awk -f script.awk | sort &gt; outfile.txt   The input data will come from a string, so I don't actually need echo.  I've got this far, can anyone explain how I get it to pipe through sort too?  p_awk = subprocess.Popen(["awk","-f","script.awk"],                           stdin=subprocess.PIPE,                           stdout=file("outfile.txt", "w")) p_awk.communicate( "input data" )   UPDATE:  Note that while the accepted answer below doesn't actually answer the question as asked, I believe S.Lott is right and it's better to avoid having to solve that problem in the first place!
10234
My problem:  I'm writing a bash script and in it I'd like to check if a given service is running.  I know how to do this manually, with $ service [service_name] status.  But (especially since the move to systemd) that prints a whole bunch of text that's a little messy to parse. I assumed there's a command made for scripts with simple output or a return value I can check.  But Googling around only yields a ton of "Oh, just ps aux | grep -v grep | grep [service_name]" results. That can't be the best practice, is it? What if another instance of that command is running, but not one started by the SysV init script?  Or should I just shut up and get my hands dirty with a little pgrep?
54930
I'm looking to write a script that takes a .txt filename as an argument, reads the file line by line, and passes each line to a command. For example, it runs command --option "LINE 1", then command --option "LINE 2", etc. The output of the command is written to another file. How do I go about doing that? I don't know where to start.
117209
What does this command do? How do I see that in the terminal because I don't have anything when I write cat passwd | awk -F':' '{printf $1}'
1170
I'm working on a simple bash script that should be able to run on Ubuntu and CentOS distributions (support for Debian and Fedora/RHEL would be a plus) and I need to know the name and version of the distribution the script is running (in order to trigger specific actions, for instance the creation of repositories). So far what I've got is this:  OS=$(awk '/DISTRIB_ID=/' /etc/*-release | sed 's/DISTRIB_ID=//' | tr '[:upper:]' '[:lower:]') ARCH=$(uname -m | sed 's/x86_//;s/i[3-6]86/32/') VERSION=$(awk '/DISTRIB_RELEASE=/' /etc/*-release | sed 's/DISTRIB_RELEASE=//' | sed 's/[.]0/./')  if [ -z "$OS" ]; then     OS=$(awk '{print $1}' /etc/*-release | tr '[:upper:]' '[:lower:]') fi  if [ -z "$VERSION" ]; then     VERSION=$(awk '{print $3}' /etc/*-release) fi  echo $OS echo $ARCH echo $VERSION   This seems to work, returning ubuntu or centos (I haven't tried others) as the release name. However, I have a feeling that there must be an easier, more reliable way of finding this out -- is that true?  It doesn't work for RedHat. /etc/redhat-release contains : Redhat Linux Entreprise release 5.5  So, the version is not the third word, you'd better use :  OS_MAJOR_VERSION=`sed -rn 's/.*([0-9])\.[0-9].*/\1/p' /etc/redhat-release` OS_MINOR_VERSION=`sed -rn 's/.*[0-9].([0-9]).*/\1/p' /etc/redhat-release` echo "RedHat/CentOS $OS_MAJOR_VERSION.$OS_MINOR_VERSION"