sed multi-line insert

unix

    Next

  • 1. Cross checking
    I wish to check in a pipe if a field in included in another file. I can do it with a shell function for one in a time. But I want it to be run through a pipe. I'm doing something like this: ps -eaf | nawk '{printf("%-8s %-8s\n", $1, $6)}' | sort -u It gives me the name of user and terminal id like this: user1 ttyp13 user1 ttyp14 user1 ttyp8 user2 ttyp1 user2 ttyp17 I have another file (ex: /tmp/userlist) that is like this: user1:xxxxxxxx user2:xxxxxxxx user4:xxxxxxxx user9:xxxxxxx user234:xxxxxxx I need to pipe "something" after my line that can cross check those 2 files. I need to check the first column of the first result with the user in the /tmp/userlist file. I know I can do : grep "^name\:" /tmp/userlist to get the user one at a time. So I just have to process all the lines separately. I'm looking in a way to transform that check in a "pipe"able format. Please help :)
  • 2. Forcing a non-zero exit status.....
    Why doesn't the following trap get executed if I have the script exit with the line: exit 1 ========================================================================== #!/usr/bin/ksh -e f_errorhandler() { print "Caught it!" } trap 'f_errorhandler' ERR echo "jjdfdsf" exit 1 ========================================================================== If I change 'exit 1' to 'false', then it works. Shouldn't 'exit 1' force a non-zero exit status and cause the trap to execute? Please help. Thanks.
  • 3. displaying (directing) to multiple terminals
    I'm in a Unix course, we are connected to a Unix server through telnet (under windows). Our instructor run a script that let all what he write and run on his computer be displayed on all our terminals , as data show to simplify explanation. Does any one know what does this script contains?? (This script is his own script so it's no an existing one)
  • 4. pushd <no arguments> versus cd <no arguments>
    In csh, tcsh or bash ... cd <no arguments> puts me in my home directory. Why does not pushd <no arguments> do the same? Is there a reason or just miss-out? Thanks in advance, -Bhushit

sed multi-line insert

Postby dillogimp » Mon, 20 Nov 2006 19:18:59 GMT

hi

I need to insert multi lines to a file but sed won't cooperate, help!
sed -i.bak "s/\(Predefined preprocessor variables.*\)/\1
cat >>confdefs.h <<_ACEOF
#define FFMPEG_VERSION $FFMPEG_VERSION
_ACEOF
/" configure

I get:
sed: -e expression #1, char 44: unterminated `s' command
thanks


Re: sed multi-line insert

Postby Bill Marcum » Mon, 20 Nov 2006 19:36:10 GMT

On 19 Nov 2006 02:18:59 -0800,  XXXX@XXXXX.COM  


Add a \ at the end of each line.

-- 
The greatest love is a mother's, then a dog's, then a sweetheart's.
		-- Polish proverb

Re: sed multi-line insert

Postby Ed Morton » Mon, 20 Nov 2006 23:33:39 GMT



lines="cat >>confdefs.h <<_ACEOF
#define FFMPEG_VERSION $FFMPEG_VERSION
_ACEOF"

awk -v lines="$lines" '1;/Predefined preprocessor variables/{print 
lines}' configure > tmp && mv tmp configure

	Ed.

Similar Threads:

1.sed to insert lines in a file.

I need to insert multiple lines into a postscript file. I think I can
use sed to do this. I actually have it working, sort of...

I need to insert 9 lines of postscript code into a postscript file
after each line starting with %%Page:

I was thinking I can use the append command with sed, but that only
works for one occurence. I need to be able to insert the lines after
each occurrence of %%Page:, any suggestions? Thanks!!

2.Need help with sed/awk cmd to insert a string in a line

Hi,

I have the following one line :

<tns:ARMLoan MortgageMarginPercent="2.4000"
NegativeAmortizationIndicator="N"
LifetimeMinimumInterestRatePercent="2.40000"
FirstInterestRateChangeDate="2016-03-01"
NextScheduledRateChangeDate="2016-04-01"
InterestRateChangeIndexLookBackPeriod="15"
NextScheduledPaymentChangeDate="2016-05-01" FirstPI
ChangeDate="2016-04-01" RateRoundingMethodCode="T"
ConversionAllowedIndicator="N" RateChangeFrequencyPeriod="1"/
>

I need to append
ARMPlanNumber="03648"
after
NextScheduledRateChangeDate="2016-04-01"

The problem is the date in NextScheduledRateChangeDate is not fixed
and will be different.

Any suggestions to achieve this in Unix would be greatly appreciated.

Thanks in advance !

-Anil
CapriTechnologies,Inc

3.sed insert character in specific position relative to end of line

I couldn't find a posting that told me exactly how to do this, but
after reading related postings and some guesswork I got there, thought
it might be useful to others too:

echo original | sed 's/..$/NEW&/' 
originNEWal

echo original | sed 's/.......$/NEW&/'
oNEWriginal

hope its useful

Rich

4.Inserting file after first occurrence of blank line with sed

I'm trying to get sed to insert file X into file Y after the first
occurrence of a blank line in file Y.

Here's the first few lines of file Y:

>From 9b3a3f2695eb4d4c509f5235e0b1860010054fa0 Mon Sep 17 00:00:00 2001
From: Timur Tabi < XXXX@XXXXX.COM >
Date: Tue, 23 Jan 2007 16:49:48 -0600
Subject: [PATCH] Abort booting if the DTB is not version 16


Signed-off-by: Timur Tabi < XXXX@XXXXX.COM >

After trying for 15 minutes, I gave up.  This is closest I got:

sed '1,/^$/ { r changelog;}' < fileX

This gives me this error, which I don't understand:

sed: -e expression #1, char 0: Unmatched `{'

Can someone tell me what I'm doing wrong?

5.insert empty lines with sed (shell script)

Hello newsgroup,

I would like to insert empty lines into a textfile via sed.
What I have is the position of the line as a shell variable.
As I tried several ways to implement this code into my script and did 
not succed, I ask for help here.
It should look somehow like the following lines, but I do not know how 
to tell sed, the line where it should insert an emty line.

linenumber=`cat $file | egrep -o -o "BLATT   2" sed -e's/:.*//g'`
sed -e '($linenumber)i\          # the problem is in this line *
\
' < oldfile > newfile

*the brackets are just to show my intention.

Any suggestions?

Thanks in advance,

Harald Steden

6. sed to insert lines in a file.

7. Sed command, Insert text in front of existing line

8. SED (or awk) If Line X 1st character NEQ B, insert newline



Return to unix

 

Who is online

Users browsing this forum: No registered users and 62 guest