Sponsored Content
Top Forums Shell Programming and Scripting Matching and Replacing file lines starting with $ Post 302913071 by tiktak292 on Wednesday 13th of August 2014 03:22:13 PM
Old 08-13-2014
Matching and Replacing file lines starting with $

Here is the task that I was presented with:
I am dealing with about a 10,000 line input deck file for an analysis. About 10 separate blocks of around 25 lines of code each need to be updated in the input deck.

The input deck (deckToChange in the code below) comes with 2 separate files. File 1 is just the blocks of code that need to be changed written consecutively (OLDFILE in the code below), and file 2 is the same blocks of code that have already been altered (NEWFILE in the code below)

The same process is going to be repeated with 1000's of input decks making the same changes, so the code needs to repeatable.

Right now, in the code I have written below, all the changes are properly made except for any line that starts with a $. the $ start to lines in the input deck occurs about 3 times per file. With the code below the lines starting with the $ are not updated with changes in the new file. I am wondering if there is anyway I can read in the lines of code from OLDFILE and NEWFILE with the $ being treated as $

Code:
 awk '
        BEGIN {
                   while ((getline name < "OLDFILE") > 0)
                            {
                             getline name2 < "NEWFILE"
                             a[name]=name2
                             }
                   }
        a[$0]   {
                    $0=a[$0]
                    }1
        '  deckToChange >newDeck

This is a rather urgent problem, and any help would be greatly appreciated.

Thanks
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to print the number of lines from a file, the starting string should be passed`

Hi , I have file, which has the below content: line 100 a b c d line300 a s d f s line200 a s d a (3 Replies)
Discussion started by: little_wonder
3 Replies

2. Shell Programming and Scripting

awk if statement matching all lines starting w/ a number

Does awk have a syntax for a range of numbers or is this the best way? if ($1 >= 0 && $1 <= 9 ) (7 Replies)
Discussion started by: Arsenalman
7 Replies

3. Shell Programming and Scripting

Finding lines matching the Pattern and their previous lines in a file

Hi, I am trying to locate the occurences of certain pattern like 'Possible network disconnect' in a text file. I can get the actual lines matching the pttern using: grep -w 'Possible network disconnect' file_name. But I am more interested in getting the timing of these events which are... (7 Replies)
Discussion started by: sagarparadkar
7 Replies

4. Shell Programming and Scripting

Read .txt file and dropping lines starting with #

Hi All, I have a .txt file with some contents as below: Hi How are you? # Fine and you? I want a script file which reads the .txt file and output the lines which does not start with #. Hi How are you? Help is highly appreciated. Please use code tags when posting data and... (5 Replies)
Discussion started by: bghosh
5 Replies

5. Shell Programming and Scripting

Replacing lines matching a multi-line pattern (sed/perl/awk)

Dear Unix Forums, I am hoping you can help me with a pattern matching problem. What am I trying to do? I want to replace multiple lines of a text file (that match a multi-line pattern) with a single line of text. These patterns can span several lines and do not always have the same number of... (10 Replies)
Discussion started by: thefang
10 Replies

6. Shell Programming and Scripting

awk Array matching and replacing from master file.

I have an awk related question that I was hoping you all could help with. I am given 2 input files named OLDFILE and NEWFILE, and a Master file named MASTERFILE. They can be seen below. OLDFILE: a a a a a f g 4 5 7 8 1 2 3 (1 Reply)
Discussion started by: tiktak292
1 Replies

7. Shell Programming and Scripting

Select only the lines of a file starting with a field which is matcing a list. awk?

Hello I have a large file1 which has many events like "2014010420" and following lines under each event that start with text . It has this form: 2014010420 num --- --- num .... NTE num num --- num... EFA num num --- num ... LASW num num --- num... (9 Replies)
Discussion started by: phaethon
9 Replies

8. UNIX for Dummies Questions & Answers

Grep -v lines starting with pattern 1 and not matching pattern 2

Hi all! Thanks for taking the time to view this! I want to grep out all lines of a file that starts with pattern 1 but also does not match with the second pattern. Example: Drink a soda Eat a banana Eat multiple bananas Drink an apple juice Eat an apple Eat multiple apples I... (8 Replies)
Discussion started by: demmel
8 Replies

9. UNIX for Dummies Questions & Answers

How to grep a line not starting with # from a file (there are two lines starting with # and normal)?

e.g. File name: File.txt cat File.txt Result: #INBOUND_QUEUE=FAQ1 INBOUND_QUEUE=FAQ2 I want to get the value for one which is not commented out. Thanks, (3 Replies)
Discussion started by: Tanu
3 Replies

10. UNIX for Beginners Questions & Answers

Grep file starting from pattern matching line

I have a file with a list of references towards the end and want to apply a grep for some string. text .... @unnumbered References @sp 1 @paragraphindent 0 2017. @strong{Chalenski, D.A.}; Wang, K.; Tatanova, Maria; Lopez, Jorge L.; Hatchell, P.; Dutta, P.; @strong{Small airgun... (1 Reply)
Discussion started by: kristinu
1 Replies
panel_above(3CURSES)					     Curses Library Functions					      panel_above(3CURSES)

NAME
panel_above, panel_below - panels deck traversal primitives SYNOPSIS
cc [ flag ... ] file ... -lpanel -lcurses [ library .. ] #include <panel.h> PANEL *panel_above(PANEL *panel); PANEL *panel_below(PANEL *panel); DESCRIPTION
panel_above() returns a pointer to the panel just above panel, or NULL if panel is the top panel. panel_below() returns a pointer to the panel just below panel, or NULL if panel is the bottom panel. If NULL is passed for panel, panel_above() returns a pointer to the bottom panel in the deck, and panel_below() returns a pointer to the top panel in the deck. RETURN VALUES
NULL is returned if an error occurs. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |MT-Level |Unsafe | +-----------------------------+-----------------------------+ SEE ALSO
curses(3CURSES), panels(3CURSES), attributes(5) NOTES
These routines allow traversal of the deck of currently visible panels. The header <panel.h> automatically includes the header <curses.h>. SunOS 5.10 31 Dec 1996 panel_above(3CURSES)
All times are GMT -4. The time now is 09:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy