awk script for pattern match and line break

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers awk script for pattern match and line break
# 1  
Old 10-05-2016
awk script for pattern match and line break

Hi,

I have input which reads like

Code:
9089.00 ----- kl jkjjljk lkkk; (909099)  9097.00 ----- HGJJHHJ jcxkjlkjvhvlk jhdkjksdfkhfskd 898.00 ----- HHHH

I am trying to do something like this - As soon as I found pattern match "XYZ.00-----" it will insert a line break to the input and will go to next line and print like below

op

Code:
9089.00 ----- kl jkjjljk lkkk; (909099)
9097.00 ----- HGJJHHJ jcxkjlkjvhvlk jhdkjksdfkhfskd
898.00 ----- HHHH

Thanks
# 2  
Old 10-05-2016
something to start with:
Code:
awk '{gsub("[0-9][0-9]*[.]00",RS "&");print}' myFile

This User Gave Thanks to vgersh99 For This Post:
# 3  
Old 10-05-2016
Code:
sed "s/\([0-9]*\.00\)/\n\1/g" input.txt

# 4  
Old 10-06-2016
Quote:
Originally Posted by itkamaraj
Code:
sed "s/\([0-9]*\.00\)/\n\1/g" input.txt

The above command will work with some versions of sed, but the standards don't say anything about the replacement string in a sed substitute command converting \n to a <newline> character in the output. Note also that the above command will also insert a <newline> (or on systems that don't convert \n to a <newline>, an n) at the start of the output. The following command won't insert anything at the start of the output and should work with any version of sed:
Code:
sed 's/ \([0-9]*\.00 \)/ \
\1/g' input.txt

where there is nothing but a<newline> character immediately after the backslash at the end of the 1st line of the above command.
This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to combine lines from line with pattern match to a line that ends in a pattern

I am trying to combine lines with these conditions: 1. First line starts with text of "libname VALUE db2 datasrc" where VALUE can be any text. 2. If condition1 is met then continue to combine lines through a line that ends with a semicolon. 3. Ignore case when matching patterns and remove any... (5 Replies)
Discussion started by: Wes Kem
5 Replies

2. Shell Programming and Scripting

Match Pattern and print pattern and multiple lines into one line

Hello Experts , require help . See below output: File inputs ------------------------------------------ Server Host = mike id rl images allocated last updated density vimages expiration last read <------- STATUS ------->... (4 Replies)
Discussion started by: tigerhills
4 Replies

3. Shell Programming and Scripting

Rearrange or replace only the second line after pattern match or pattern match

Im using the command below , but thats not the output that i want. it only prints the odd and even numbers. awk '{if(NR%2){print $0 > "1"}else{print $0 > "2"}}' Im hoping for something like this file1: Text hi this is just a test text1 text2 text3 text4 text5 text6 Text hi... (2 Replies)
Discussion started by: invinzin21
2 Replies

4. Shell Programming and Scripting

Match pattern and print the line number of occurence using awk

Hi, I have a simple problem but i guess stupid enough to figure it out. i have thousands rows of data. and i need to find match patterns of two columns and print the number of rows. for example: inputfile abd abp 123 abc abc 325 ndc ndc 451 mjk lkj... (3 Replies)
Discussion started by: redse171
3 Replies

5. Shell Programming and Scripting

awk print pattern match line and following lines

Data: Pattern Data Data Data Data Data Data Data Data Data ... With awk, how do I print the pattern matching line, then the subsequent lines following the pattern matching line. Varying number of lines following the pattern matching line. (9 Replies)
Discussion started by: dmesserly
9 Replies

6. Shell Programming and Scripting

Awk-sed help : to remove first and last line with pattern match:

awk , sed Experts, I want to remove first and last line after pattern match "vg" : I am trying : # sed '1d;$d' works fine , but where the last line is not having vg entry it is deleting one line of data. - So it should check for the pattern vg if present , then it should delete the line ,... (5 Replies)
Discussion started by: rveri
5 Replies

7. Shell Programming and Scripting

how do I break line in a file when a pattern is matched ?

Hi All, I am stuck for quite sometime now. Below is a line in my file - GS|ED|001075|001081|20110626|1806|100803|X|004010ST|130|100803001 This line occurs only once and it is the second line. I have to break this line into two lines from ST (bold) such that it looks like -... (5 Replies)
Discussion started by: ihussain
5 Replies

8. Shell Programming and Scripting

pattern match .com in awk script

guys ! I want to search .com,.html files ..... how do I match pattern...? here's wht I hv written if ( $i ~ /.com/ ) even escaping it doesn't help if ( $i ~ /\.com/ ) (2 Replies)
Discussion started by: shreeprabha
2 Replies

9. Shell Programming and Scripting

Awk script to match pattern till blank line

Hi, I need to match lines after a pattern, upto the first blank line. Searched in web and some forums but coulnt find the answer. where <restart_step> = 10 -- Execute query 20 -- Write the contents to the Oracle table 30 -- Writing Contents to OUTPUT... (7 Replies)
Discussion started by: justchill
7 Replies

10. Shell Programming and Scripting

AWK break string into fields + pattern match

I am trying to break a string into separate fields and print the field that matches a pattern. I am using awk at the moment and have gotten this far: awk '{for(i=1;i<=NF;++i)print "\t" $i}' longstring This breaks the string into fields and prints each field on a separate line. I want to add... (2 Replies)
Discussion started by: Moxy
2 Replies
Login or Register to Ask a Question