Sponsored Content
Top Forums Shell Programming and Scripting [awk] find pattern, change next two lines Post 302897744 by origamisven on Tuesday 15th of April 2014 04:52:08 PM
Old 04-15-2014
[awk] find pattern, change next two lines

Hi, hope you can help me... It seems like a straightforward problem, but I haven't had any success so far using my basic scripting and awk "skills":

I need to find a pattern /VEL/ in an input file that looks like this:

Code:
 1110SOL     OW25489   1.907   7.816  26.338 -0.4365  0.4100 -0.0736
 1110SOL    HW125490   1.890   7.829  26.435  0.3507  0.4216  0.0705
 1110SOL    HW225491   1.945   7.724  26.323  0.0656  0.6460 -0.2797
 1111VEL     OW25492   4.172   7.242   6.227  0.4897 -1.0759  0.7407
 1111SOL    HW125493   4.231   7.300   6.284 -1.1002 -0.8260  1.3902
 1111SOL    HW225494   4.076   7.266   6.243 -0.8879 -1.4622  1.1007
 1112SOL     OW25495   0.578   1.347  21.833 -0.3603 -0.4613 -0.2495
 1112SOL    HW125496   0.550   1.375  21.741 -0.2047  1.9848  0.3727
 1112SOL    HW225497   0.506   1.291  21.874 -0.7886 -0.8859 -1.5335

...and then replace the SOL in the following two lines with VEL, so it looks like this:

Code:
 1110SOL     OW25489   1.907   7.816  26.338 -0.4365  0.4100 -0.0736
 1110SOL    HW125490   1.890   7.829  26.435  0.3507  0.4216  0.0705
 1110SOL    HW225491   1.945   7.724  26.323  0.0656  0.6460 -0.2797
 1111VEL     OW25492   4.172   7.242   6.227  0.4897 -1.0759  0.7407
 1111VEL    HW125493   4.231   7.300   6.284 -1.1002 -0.8260  1.3902
 1111VEL    HW225494   4.076   7.266   6.243 -0.8879 -1.4622  1.1007
 1112SOL     OW25495   0.578   1.347  21.833 -0.3603 -0.4613 -0.2495
 1112SOL    HW125496   0.550   1.375  21.741 -0.2047  1.9848  0.3727
 1112SOL    HW225497   0.506   1.291  21.874 -0.7886 -0.8859 -1.5335

Thanks for any help.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find required files by pattern in xml files and the change the pattern on Linux

Hello, I need to find all *.xml files that matched by pattern on Linux. I need to have written the file name on the screen and then change the pattern in the file just was found. For instance. I can start the script with arguments for keyword and for value, i.e script.sh keyword... (1 Reply)
Discussion started by: yart
1 Replies

2. Shell Programming and Scripting

awk to find pattern and add lines

My file goes like this: SID_LIST_HOSTNAME_LISTENER_3 = (SID_LIST = (SID_DESC = (SID_NAME = ORA0008) (ORACLE_HOME = /opt/oracle/product/ORA0008) (ENVS = "LD_LIBRARY_PATH=/opt/oracle/product/ORA0008/lib") ) (SID_DESC = (SID_NAME = ORA0007) ... (4 Replies)
Discussion started by: jpsingh
4 Replies

3. Shell Programming and Scripting

Find and change the lines in the file.

Hi Everyone, I have a JIL (Job Information Language) Definition for Several Jobs in a file. I would like to do the following: insert_job: KS_INT_BIZ_INT job_type: c command: /home/filter/script.sh INT machine: MACHINE owner: filter permission: gx,mx date_conditions: 1 days_of_week:... (3 Replies)
Discussion started by: filter
3 Replies

4. Shell Programming and Scripting

how to find pattern and discard lines before it?

Hi all, I'd like to search a file for the first occurence of the phrase "PLASTICS THAT EXPIRE" and then discard all the lines that came before it. Output the remainder to a new file. Operating system is hp-ux. I've searched for usual awk and sed one liners but can't find a solution. Thank... (4 Replies)
Discussion started by: Scottie1954
4 Replies

5. Shell Programming and Scripting

sed -- Find pattern -- print remainder -- plus lines up to pattern -- Minus pattern

The intended result should be : PDF converters 'empty line' gpdftext and pdftotext?xml version="1.0"?> xml:space="preserve"><note-content version="0.1" xmlns:/tomboy/link" xmlns:size="http://beatniksoftware.com/tomboy/size">PDF converters gpdftext and pdftotext</note-content>... (9 Replies)
Discussion started by: Klasform
9 Replies

6. Shell Programming and Scripting

Using awk or sed to find a pattern that has lines before and after it

Dear gurus, Please help this beginner to write and understand the required script. I am looking for useing awk for sed. I have a few thousand lines file whose contain are mostly as below and I am trying to achieve followings. 1. Find a string, say user1. Then hash the line containing the... (6 Replies)
Discussion started by: ran_bon_78
6 Replies

7. Shell Programming and Scripting

Find pattern; grep n lines before and after

Hi, I need help to grep a specific part of a log file (bold). 24/2/2017-16:57:17.056 frosti-1 M3UA-Tx: } 24/2/2017-16:57:17.056 frosti-1 M3UA-Tx: extensionContainer <Not Present> 24/2/2017-16:57:17.056... (8 Replies)
Discussion started by: vasil
8 Replies

8. UNIX for Beginners Questions & Answers

find pattern matches in consecutive lines in certain fields-awk

I have a text file with many thousands of lines, a small sample of which looks like this: InputFile:PS002,003 D -1 5 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 6 6 -1 -1 -1 -1 0 509 0 PS002,003 PSQ 0 1 7 18 1 0 -1 1 1 3 -1 -1 ... (5 Replies)
Discussion started by: jvoot
5 Replies

9. Shell Programming and Scripting

Find specific pattern and change some of block values using awk

Hi, Could you please help me finding a way to replace a specific value in a text block when matching a key pattern ? I got the keys and the values from a command similar to: echo -e "key01 Nvalue01-1 Nvalue01-2 Nvalue01-3\nkey02 Nvalue02-1 Nvalue02-2 Nvalue02-3 \nkey03 Nvalue03-1... (2 Replies)
Discussion started by: alex2005
2 Replies

10. UNIX for Beginners Questions & Answers

awk to remove pattern and lines above pattern

In the awk below I am trying to remove all lines above and including the pattern Test or Test2. Each block is seperated by a newline and Test2 also appears in the lines to keep but it will always have additional text after it. The Test to remove will not. The awk executed until the || was added... (2 Replies)
Discussion started by: cmccabe
2 Replies
GREP(1) 						      General Commands Manual							   GREP(1)

NAME
grep - search a file for a pattern SYNOPSIS
grep [ option ... ] pattern [ file ... ] DESCRIPTION
Grep searches the input files (standard input default) for lines (with newlines excluded) that match the pattern, a regular expression as defined in regexp(6). Normally, each line matching the pattern is `selected', and each selected line is copied to the standard output. The options are -c Print only a count of matching lines. -h Do not print file name tags (headers) with output lines. -i Ignore alphabetic case distinctions. The implementation folds into lower case all letters in the pattern and input before interpre- tation. Matched lines are printed in their original form. -l (ell) Print the names of files with selected lines; don't print the lines. -L Print the names of files with no selected lines; the converse of -l. -n Mark each printed line with its line number counted in its file. -s Produce no output, but return status. -v Reverse: print lines that do not match the pattern. Output lines are tagged by file name when there is more than one input file. (To force this tagging, include /dev/null as a file name argument.) Care should be taken when using the shell metacharacters $*[^|()= and newline in pattern; it is safest to enclose the entire expression in single quotes '...'. SOURCE
/sys/src/cmd/grep.c SEE ALSO
ed(1), awk(1), sed(1), sam(1), regexp(6) DIAGNOSTICS
Exit status is null if any lines are selected, or non-null when no lines are selected or an error occurs. GREP(1)
All times are GMT -4. The time now is 05:18 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy