How to write a script containg more than 1 command
Hi all,
I have a file that I want to do some operations on, 1st I want to grep certain number then I want to use awk to get numbers between 0 - 9 then I am going to use egrep to get the values X or Y I have all commands but all they work separate, I want to see the script that run all these commands then output me the result :) Thanks |
Use the pipe |
Ex: Quote:
|
Or you can play a little bit and simply put all your commands into a file
do chmod u+x <your_file> you now created script "your_file", you can run it like this ./your_file |
Quote:
grep 012[01-2]=x data.txt egrep -w 'A|N' data.txt awk -v x=5 ' $2 <= x ' data.txt here only grep & awk are done the egrep result is not processed |
is the data file like
A bla bla bla A bla bla bla N bla bla bla ? or Ablablabla Nblablabla ? |
Quote:
|
Solved thanks
|
I run it and egrep works fine, instead the grep didnt executed, im not even sure what it does
i solved it changing grep 012[01-2]=x data.txt to grep 012[01-2] data.txt, have no idea why '=x' was there for ! ?? to make your script more flexible you can use arguments instead static path in your script change data.txt to $1 and run script as ./script.sh some_file |
Please use [code][/code] tags around your code and data, to preserve formatting and to improve readability. Please do not use quote tags, colors, or other fancy formatting.
It's a good idea to quote your grep patterns, especially if it contains characters that are special to the shell. Actually, there's generally no need to use grep and awk (or sed) together. awk is a full text-processing scripting language and can do all the pattern matching on its own. Code:
Again, if you would post an actual example of the text and the part you want to extract from it, we could help you design the proper command for it. Here are a few useful awk references: http://www.grymoire.com/Unix/Awk.html http://www.gnu.org/software/gawk/man...ode/index.html http://www.pement.org/awk/awk1line.txt http://www.catonmat.net/blog/awk-one...ined-part-one/ |
Quote:
|
Wow! This is a prime example of why this forum is so awesome. The speed and clarity which this issue was solved was phenomenal. I agree with Grail, that ahmed_as8 should consider sharing the solution. Peace out, penguinos!
|
All times are GMT -5. The time now is 01:06 PM. |