Combine several commands in a bash script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Combine several commands in a bash script
# 8  
Old 10-12-2013
Quote:
Originally Posted by georgi58
Code:
awk -F\| '/http:/{print $1 > ("sitelist_PR" $2 ".txt")}' file

Thank you for your input.
Command works in a bit different way that I need and
creates output files from sitelist_PR .txt to sitelist_PR9 .txt, actually I needed only to PR.6, but that is fine.

There are two things however that are different from the desire output:
- each file contains only url-s with PR same as in the filename i.e. sitelist_PR1 .txt contains url-s with PR1 only - my goal was to remove those url-s and have all the rest higher than PR1 in this file;
- when I look at the file name I see blank space before .txt
[..]
So more like this?
Code:
awk -F\| '/http:/{for(i=1; i<=6; i++) if($2>=i)print $1 > ("sitelist_PR" i ".txt")}' file

This User Gave Thanks to Scrutinizer For This Post:
# 9  
Old 10-12-2013
Quote:
Originally Posted by MadeInGermany
Save whatever commands to a file, and you can run it with
Code:
bash file

works!! thank you very much.

---------- Post updated at 04:14 PM ---------- Previous update was at 04:10 PM ----------

Quote:
Originally Posted by Scrutinizer
So more like this?
Code:
awk -F\| '/http:/{for(i=1; i<=6; i++) if($2>=i)print $1 > ("sitelist_PR" i ".txt")}' file

this works fine with just one small detail: is there any way to preserve "|<number>" at the end of each line.

thank you very much.
# 10  
Old 10-12-2013
Quote:
Originally Posted by georgi58
[..]
this works fine with just one small detail: is there any way to preserve "|<number>" at the end of each line.

thank you very much.
Yes, use print instead of print $1. You are welcome..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using commands within bash script

The purpose of enclosed script is to execute selected command and output success or failure in whiptail msgBox Works as expected when command returns zero to msgBox. I cannot figure out how to continue / automate my script when command expects reply to continue / terminate. I am doing it... (2 Replies)
Discussion started by: annacreek
2 Replies

2. Shell Programming and Scripting

Combine 2 Commands

Hello, I have the following code. I wonder if it can be combined into 1 command. y=`ls -1| tail -n 1` m=${y%.abc} Thank you. (3 Replies)
Discussion started by: april
3 Replies

3. Shell Programming and Scripting

Combine multiple commands

I have the following sh-script: konsole -T todo -e vi todo.txt & konsole -T window1 -e ssh user@server & konsole -T window2 -e ssh user@server2 -e cd directory & The first two lines are working fine. The first opens a txt-file, the second opens a ssh-connection. The third line... (6 Replies)
Discussion started by: andre666
6 Replies

4. Shell Programming and Scripting

How to combine 2 bash script into 1?

Hi all, I’ve quick question on bash scripting. Here is my initial input. This is just an example. The value could be different numbers/ip addresses. host.txtFinal output should be like this. output-final.txt In order to have this, I’ve 2 different scripts. The first one is just to... (6 Replies)
Discussion started by: type8code0
6 Replies

5. Shell Programming and Scripting

How to create an executable bash script for these commands?

I wish to create an executable bash script that will run the following commands as root, that is, using sudo su iptables-save | awk '/^ / { print $1 } /^:+ / { print $1 " ACCEPT" ; } /COMMIT/ { print $0; }' | iptables-restoreMy first attempt at bash... (9 Replies)
Discussion started by: thixeqi
9 Replies

6. Shell Programming and Scripting

How to combine awk and bash commands in script ?

Dear friends, I am just trying write one script using 2 files one file will contain details like below #X SERVER X LOCATION URL="http://www.abcd.com" FILENAME="abc.txt" ID_NAME="myabc_xyz" SERVER_PATH="/usr/local/dummy/html/....." #Y SERVER Y LOCATION URL="http://www.xyz.com"... (10 Replies)
Discussion started by: Akshay Hegde
10 Replies

7. Shell Programming and Scripting

Can I combine these two commands into one?

sed -e :a -e 's/<*>//g;/</N;//ba' a2.html -removes html tags and sed -i 's/YOURS TRULY/Joe Bob/' a2.html Replaces a string with another string can i make it into one string? (2 Replies)
Discussion started by: boyboy1212
2 Replies

8. Shell Programming and Scripting

Execute ssh commands through bash script

Hi all! I am trying to write a script that will check if a certain directory is available at several different nodes and then do stuff in it ..... On the beginning of the script I give as a variable the directory and the number of the nodes and then I loop like this: for... (3 Replies)
Discussion started by: idet2
3 Replies

9. Shell Programming and Scripting

how to run non-standard commands in bash script?

Hello All. I suspect that this will be a clear noob question, but I haven't been able to figure it out using the usual methods, so I turn to you. I've written a script to create input files for the quantum chemistry program NWCHEM. Generally you create an input file and then execute it by... (12 Replies)
Discussion started by: EinsteinMcfly
12 Replies

10. UNIX for Dummies Questions & Answers

Combine commands

Hi, i tried to combine grep with find and it didnt work grep 'find dirname filename" i also would like that the file will be sorted in the way. thanks a lot. (2 Replies)
Discussion started by: Spoiler
2 Replies
Login or Register to Ask a Question