Sponsored Content
Top Forums Shell Programming and Scripting sed/awk script selective insert between lines Post 302301973 by dunstonrocks on Sunday 29th of March 2009 03:21:43 PM
Old 03-29-2009
SED/ AWK to do selective insert

I would appreciate if any one could give a handy one-liner in sed/awk to insert a line between two lines if and only if a condition is NOT fulfilled

sample input record:
*field* 1
*field* 2
*field* 3

*field* 1
*field* 3


sample output record:
*field* 1
*field* 2
*field* 3

*field* 1
*field* 2
*field* 3


insert word between two lines if word does not occur
else
leave as is.

I know to do this in perl, but I am just looking for an awk/sed command that would accomplish the same.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sed insert and Change lines help needed

Hi, How can i use insert and change command in ksh shell. I am using : sed -e '1i\TEXTTOBEINSERTED\' FILENAME But there is no effect... Also sed -e 'c\thisischange\' Filename Please Explain how to proceed?? (2 Replies)
Discussion started by: JunkYardWars
2 Replies

2. Shell Programming and Scripting

sed/awk to insert multiple lines before pattern

I'm attempting to insert multiple lines before a line matching a given search pattern. These lines are generated in a separate function and can either be piped in as stdout or read from a temporary file. I've been able to insert the lines from a file after the pattern using: sed -i '/pattern/... (2 Replies)
Discussion started by: zksailor534
2 Replies

3. Shell Programming and Scripting

sed - insert two lines

I have done this sed command to insert one line after a specific string is found: sed '/patternstring/ a\ new line string' file1 But how do I insert two lines? This is not possible: sed '/patternstring/ a\ new line string \a new line string 2' file1 (2 Replies)
Discussion started by: locoroco
2 Replies

4. Shell Programming and Scripting

Insert few lines above a match using sed, and within a perl file.

Greetings all, I am trying to match a string, and after that insert a few lines above that match. The string is "Version 1.0.0". I need to insert a few lines ONLY above the first match (there are many Version numbers in the file). The rest of the matches must be ignored. The lines I need to... (2 Replies)
Discussion started by: nagaraj s
2 Replies

5. Shell Programming and Scripting

sed insert text 2 lines above pattern

Hi I am trying to insert a block of text 2 lines above a pattern match using sed eg #Start of file entry { } #End of file entry new bit of text has to be put in just above the } eg #Start of file entry { New bit of text } #End of file entry (7 Replies)
Discussion started by: eeisken
7 Replies

6. UNIX for Dummies Questions & Answers

Selective Replacements: Using sed or awk to replace letters with numbers in a very specific way

Hello all. I am a beginner UNIX user who is using UNIX to work on a bioinformatics project for my university. I have a bit of a complicated issue in trying to use sed (or awk) to "find and replace" bases (letters) in a genetics data spreadsheet (converted to a text file, can be either... (3 Replies)
Discussion started by: Mince
3 Replies

7. Shell Programming and Scripting

How to substract selective values in multi row, multi column file (using awk or sed?)

Hi, I have a problem where I need to make this input: nameRow1a,text1a,text2a,floatValue1a,FloatValue2a,...,floatValue140a nameRow1b,text1b,text2b,floatValue1b,FloatValue2b,...,floatValue140b look like this output: nameRow1a,text1b,text2a,(floatValue1a - floatValue1b),(floatValue2a -... (4 Replies)
Discussion started by: nricardo
4 Replies

8. UNIX for Dummies Questions & Answers

sed command to Insert a line before the last four lines of the file

By using sed command, How to insert a new line before the last four lines of the file. Old Line Old Line NEW LINE! Old Line Old Line Old Line Old Line (8 Replies)
Discussion started by: wridler
8 Replies

9. Shell Programming and Scripting

Sed; insert text two lines above match

Hi! Considering below text, how would I use sed to insert text right below the v0005-line, using the SEPARATOR-line as a pattern to search for, so two lines above the separator? I can do it right above the separator, but not 2 lines... # v0004 - Some text # v0005 - More text #... (5 Replies)
Discussion started by: indo1144
5 Replies

10. Shell Programming and Scripting

Using sed to insert text between lines

Hello, I am trying to insert a section of text between lines in another text file. The new lines to be inserted are: abcd.efgh.zzzz=blah abcd.efgh.xxxx=blah Where N = 0 to 2 Original File: abcd.efgh.wwxx=aaaaa abcd.efgh.yyzz=bbbbb abcd.efgh.wwxx=aaaaa abcd.efgh.yyzz=bbbbb... (3 Replies)
Discussion started by: tsu3000
3 Replies
FORMS(3)						   BSD Library Functions Manual 						  FORMS(3)

NAME
field_back, field_fore, field_pad, set_field_back, set_field_fore, set_field_pad -- form library LIBRARY
Curses Form Library (libform, -lform) SYNOPSIS
#include <form.h> chtype field_back(FIELD *field); chtype field_fore(FIELD *field); int field_pad(FIELD *field); int set_field_back(FIELD *field, chtype attribute); int set_field_fore(FIELD *field, chtype attribute); int set_field_pad(FIELD *field, int pad); DESCRIPTION
Calling the function field_back() will return the character attributes that will be applied to a field that is not the current field, these attributes can be set by the set_field_back() function. The field_fore() function returns the character attributes that will be used to indicate that a field is the currently active one on the form, this attribute may be set by using the set_field_fore() function. The pad character for a field is the character that will be printed in all field locations not occupied with actual field contents. The pad charac- ter can be retrieved by calling the field_pad() function, the pad character is set by using the set_field_pad() function. RETURN VALUES
Functions returning pointers will return NULL if an error is detected. The functions that return an int will return one of the following error values: E_OK The function was successful. SEE ALSO
curses(3), forms(3) NOTES
The header <form.h> automatically includes both <curses.h> and <eti.h>. BSD
January 1, 2001 BSD
All times are GMT -4. The time now is 10:46 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy