Sponsored Content
Full Discussion: Simplifying my script
Top Forums UNIX for Advanced & Expert Users Simplifying my script Post 302398101 by amitranjansahu on Tuesday 23rd of February 2010 11:43:05 PM
Old 02-24-2010
Just add a if condition. If the file "rm1.txt" is there then simply append the output to file else redirect.

Code:
if [ -e rm1.txt ]
then

grep "|" sRMR_6.txt >> rm1.txt
grep "|" sRMR_7.txt >> rm1.txt
grep "|" sRMR_8.txt >> rm1.txt
grep "|" sRMR_9.txt >> rm1.txt
grep "|" sRMR_10.txt >> rm1.txt
grep "|" sRMR_11.txt >> rm1.txt
grep "|" sRMR_12.txt >> rm1.txt
grep "|" sRMR_13.txt >> rm1.txt
grep "|" sRMR_14.txt >> rm1.txt
grep "|" sRMR_15.txt >> rm1.txt
grep "|" sRMR_16.txt >> rm1.txt
grep "|" sRMR_17.txt >> rm1.txt
grep "|" sRMR_18.txt >> rm1.txt
grep "|" sRMR_19.txt >> rm1.txt
grep "|" sRMR_20.txt >> rm1.txt
grep "|" sRMR_21.txt >> rm1.txt
grep "|" sRMR_22.txt >> rm1.txt
grep "|" sRMR_23.txt >> rm1.txt 

else

grep "|" sRMR_6.txt > rm1.txt
grep "|" sRMR_7.txt >> rm1.txt
grep "|" sRMR_8.txt >> rm1.txt
grep "|" sRMR_9.txt >> rm1.txt
grep "|" sRMR_10.txt >> rm1.txt
grep "|" sRMR_11.txt >> rm1.txt
grep "|" sRMR_12.txt >> rm1.txt
grep "|" sRMR_13.txt >> rm1.txt
grep "|" sRMR_14.txt >> rm1.txt
grep "|" sRMR_15.txt >> rm1.txt
grep "|" sRMR_16.txt >> rm1.txt
grep "|" sRMR_17.txt >> rm1.txt
grep "|" sRMR_18.txt >> rm1.txt
grep "|" sRMR_19.txt >> rm1.txt
grep "|" sRMR_20.txt >> rm1.txt
grep "|" sRMR_21.txt >> rm1.txt
grep "|" sRMR_22.txt >> rm1.txt
grep "|" sRMR_23.txt >> rm1.txt

fi

 

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help in simplifying a sed command

I need to do a substitution: CPF to ,C,P,F, CPM to ,C,P,M, SPF to ,S,P,F etc. I can do each of them with separate substitutions e.g. s/CPF/,C,P,F/ but I'd like to know if there is a more elegant solution. In general, how can I use the results of the search in the substitution, ... (3 Replies)
Discussion started by: wvdeijk
3 Replies

2. Shell Programming and Scripting

Simplifying the For loop

Is there a way to simplify stating 1 through to 10, for example in a for loop construct? for x in 1 2 3 4 5 6 7 8 9 10 do .... done I have tried (1-10) with no luck.. thanks (2 Replies)
Discussion started by: sirtrancealot
2 Replies

3. Shell Programming and Scripting

simplifying awk

tcpdump -nr testdump|awk '!/:/;gsub(/^+|+$/,""){print $3};a!~$0;{a=$0};{print $3};!/length/;/./;!/11\:/;!/8 7 6 5 4 3 2 1/;!/UDP/{b=$0} END {for (j=i-1; j>=0; ) print b };{for (i=NF; i>0; i--) printf("%s ",i);printf ("\n")}' *NOTE IN j>=0 the ; ) was given a space since a smiley is showing up...... (1 Reply)
Discussion started by: sil
1 Replies

4. Shell Programming and Scripting

Undefined "n" value and simplifying script

I have a very 'dirty' bash script that is working and looks like this: #!/bin/bash for i in {1..n} do mv block${i} infile ./dnadist <<-EOF D Y EOF rm infile mv outfile Result${i} mv Result${i} infile ./neighbor <<-EOF Y EOF rm infile rm outfile mv outtree Result${i}... (8 Replies)
Discussion started by: Xterra
8 Replies

5. Shell Programming and Scripting

need help simplifying an if statement

the code below is a small fragment of the actual line, in fact i have about 20 values i'm comparing and want to know if it can be simplified. other than the x.xx.xx format of the value they have nothing in common if || || ; then do this else do this fiany suggestions? (6 Replies)
Discussion started by: crimso
6 Replies

6. Shell Programming and Scripting

Simplifying sed/tr

Hi all, I don't have much experience with shell scripting and I was wondering if there's a shorter way to write this. Basically, given a list of strings separated by new lines, I want to prepend each string with a prefix and separate the strings with commas i.e. stra strb strc becomes... (3 Replies)
Discussion started by: vshan
3 Replies

7. UNIX for Beginners Questions & Answers

Simplifying awk script using multiple "|"

I have the following script: awk -F "," '{ if ( $4 > 450 && $4 < 550 && $5 > 0.5 ) print $2, $5; else print $2, "0" }' test.txt | awk '{a+=$2}END{for(i in a){print i, a}}' | sort -nk 1.2 | sed 1,2d and a bunch of files that look like the test file attached here. I am outputting all... (2 Replies)
Discussion started by: Xterra
2 Replies

8. UNIX for Beginners Questions & Answers

Simplifying awk/sed short pipeline

I have a file like this: FileName,Well,Sample Description,Size ,Calibrated Conc. ,Assigned Conc. ,Peak Molarity ,Area,% Integrated Area,Peak Comment,Observations 2017-11-15 - 13.49.50.D1000,EL1,Electronic Ladder,25,5.22,,321,0.803,,,Lower Marker 2017-11-15 - 13.49.50.D1000,EL1,Electronic... (6 Replies)
Discussion started by: Xterra
6 Replies
INSTALLSIEVE(1) 					      General Commands Manual						   INSTALLSIEVE(1)

 *

NAME
installsieve - user utility for managing sieve scripts SYNOPSIS
installsieve DESCRIPTION
installsieve is a utility that allows users to manage their sieve scripts kept on the server. OPTIONS
-v <name> View script with the given name. The script if retrieved sucessfully is output to standard output. -l List all of the scripts currently on the server. If one of the scripts is active a arrow is printed indicating that it is the active script. -p <port> Port to connect to. If left off this defaults to "sieve" as defined in /etc/services. -i <file> Install a file onto the server. If a script with the same name already exists on the server it is overwritten. Upon sucessfully putting the script on the server the script is set active. If <file> has the extension .script it is chopped when put on the server since sieve names may not contain a '.'. -a <name> Set <name> as the active script. The list of available names can be obtained from the '-l' option.. -d <name> Delete the sieve script on the server with <name>. -m <mechanism> Force installsieve to use <mechanism> for authentication. If not specified the strongest authentication mechanism is chosen. -g <name> Get the sieve script with <name> and save it to disk with a ".script" extension. If a file with that name already exists it is overwritten. -u <user> Userid/Authname to use for authentication; by default, the current user. CMU
Project Cyrus INSTALLSIEVE(1)
All times are GMT -4. The time now is 07:15 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy