Error in shell script and how to write to a file [closed] - linux

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am writing a shell script that is extracting the data from a command:
I have tried running the script in both the vi and vim editor. But everything in vain.
Please help me out. And how write the output of this in a file.
It may be noted that this is just a starting point so the script will produce multiple files so
I cannot write:
Script_name > filename

I think this question is fine now, the input file is good enough after edit, I can fully understand what you ask for now.
With awk, you need learn to use 2-d array, it will simplify the code.
awk 'BEGIN{print "Instance id Name Owner Cost.centre"}
/TAG/{split($0,a,FS);a[4]=tolower(a[4]);$1=$2=$3=$4="";b[a[3],a[4]]=$0;c[a[3]]}
END{for (i in c) printf "%-18s%-26s%-14s%-20s\n",i,b[i,"name"],b[i,"owner"],b[i,"cost.center"]}' file
Instance id Name Owner Cost.centre
i-e1cfc499 Memcached
i-7f4b9300 Test_LB01_Sachin
i-c4260db8 Rishi_Win_SAML Rishi Pandey
i-fb5ca283 CLIQR-DO NOT TOUCH mataa 1234

Related

Add rows in an excel file with a shell script [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 days ago.
Improve this question
I'm trying to create a shell script that creates an excel output file and add data in it.
I don't know how to add rows in this excel file. The goal being that the data will be added in separate cells.
I tried many instruction that i found in the web, but none worked for me.
the file after my script would be like below:
Is there an instruction to do this please?
Thanks for your help
This code worked for me:
touch Output.xls
chmod 777 Output.xls
printf "Date\tTotal number\tSuccessful number\tFailed numbe\n" >> Output.xls
printf "2016_05_11\t20\t5\t15\n" >> Output.xls
printf "2016_06_30\t30\t16\t14\n" >> Output.xls
The output file is as below:
enter image description here

whenever I use "sudo su", i'm getting "bash: export : = not a valid identifier". I'm new to linux. Please excuse for not being more informative [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I'm using UBUNTU 20.04,wayland. However I'm getting root privileges after that two messages.
The root .bashrc file has a line that looks like this:
export PATH = /snap/bin:/usr/local/sbin/...
Get rid of the spaces around the =.
export PATH=/snap/bin:/usr/local/sbin/...

Assign a value to a variable which has =," [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I want to print the line which has below value in my text file(ex: file.txt).
I have tried multiple ways but no luck. Can someone please help me the right command.
selector="((Source IN ('VPS','VPSLegacy')) OR (JMS_TIBCO_SENDER='rig'))"
Please note that i need to use entire above value to check in the file.
The easiest way to assign a literal (potentially containing quotes or other shell syntax) to a variable, even though it comes with a performance penalty, is to use a quoted heredoc:
content=$(cat <<'EOF'
selector="((Source IN ('VPS','VPSLegacy')) OR (JMS_TIBCO_SENDER='rig'))"
EOF
)
echo "Value is: <$content>"
...correctly emits as output:
Value is: <selector="((Source IN ('VPS','VPSLegacy')) OR (JMS_TIBCO_SENDER='rig'))">

Batch files - names [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I have a code that looks for png files with a specific pattern on the desktop and moves them to another directory.
While going over the files, I want to check if there is the pattern in the name.
This is how I did it:
for %%f in (C:\Users\user\Desktop\*.png) do (
if %%f==Hearthstone Screenshot*.png (
move %%f C:\destination\
)
)
Note: All the needed files start with Hearthstone Screenshot then some numbers.
My main problem is in line 2. I can't make it work.
Depending upon you needs, perhaps this is what you're looking for…
#RoboCopy "%UserProfile%\Desktop" "%UserProfile%\Desktop\HearthStone_Screenshots" "HearthStone Screenshot*.png" /MOV>Nul 2>&1
This should automatically create the holding directory, HearthStone_Screenshots if it doesn't already exist.
Note:I have corrected what I'm assuming to be your very poor spelling issues. If those files and directories should be named using ea instead of ee please re-adjust as necessary.
What's wrong with this:
move C:\Users\user\Desktop\HearthstoneScreanshot*.png C:\Users\user\Desktop\Hearthstonescreanshot\

Temprarly change $PATH only for the script run [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I hope that you can help me with the following problem: I want to implement a script that requires that $PATH variables has missing . value changes in it.
The point of the script is to find requested files and copy them to parent directory. I can do this using -execdir, but the problem is that . is defined in the $PATH.
Can you please tell me how can I provide a temporary replacement for the $PATH variable that can be valid only for the script execution.
Thanks
The shell allows you to set environment variables of an executable by passing them to the invocation. Like this:
PATH="/foo/bar" program

Resources