![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| grep the line only if next line matches | pbsrinivas | Shell Programming and Scripting | 11 | 07-10-2007 05:51 AM |
| Printing the following line that matches an string | jgarcia | Shell Programming and Scripting | 7 | 05-09-2007 10:31 PM |
| Select matches between line number and end of file? | Jerrad | Shell Programming and Scripting | 4 | 05-24-2006 04:50 AM |
| Appending to filename a string of text grep finds | HLee1981 | Shell Programming and Scripting | 3 | 09-06-2005 11:44 AM |
| String in text matches folder name | shackman66 | Shell Programming and Scripting | 2 | 05-05-2004 02:46 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
I'm currently digging for a way to append a line to a text file where each line begins with the word "setmqaut". This is a continuation of my IBM MQSeries backup script I'm working on to make my life a little easier.
What I would like to do is have each line that looks like this: setmqaut -m TEST -n SYSTEM.DEFAULT.PROCESS -t process -g root +inq +set +chg +dlt +dsp Look like this: setmqaut -m TEST -n SYSTEM.DEFAULT.PROCESS -t process -g root +inq +set +chg +dlt +dsp >> $LOGFILE I'm still trying to figure out how to do a grep and make a for go through and add this line to each line that starts with the setmqaut command. I'm guessing sed would be the best way to do this, but unfortunately I'm not as experienced as I'd like with it. Any suggestions would rock! In the meantime, it's back to google for me. |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
sed '/setmqaut/s/$/>> $LOGFILE/' textFile
|
|
#3
|
|||
|
|||
|
Quote:
What I kept trying was this: cat test.sh | sed '/setmqaut/ a\ linetoinsert' > demo.txt And tried a whole bunch of things in place of a\ to see if it would append to the end of the line, but I can't seem to find a simple option to put in it's place that would do it. |
|
#4
|
|||
|
|||
|
What vger99 showed you was in short form a fundamental mechanism for regexps, which is mostly unknown and/or not used to its full capability:
Code:
/<expression1>/ {
command 1
command 2
...
}
So his sed-oneliner reads in fact: "apply to all lines containing 'setmqaut' the following: replace the end-of-line ('$') with the string '>> ...'" The a-subcommand gets used only, when you want to append a certain piece of text after a complete line. bakunin |
|
#5
|
|||
|
|||
|
Quote:
|
|||
| Google The UNIX and Linux Forums |