awk/sed Command: To Parse Stament between 2 numbers


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk/sed Command: To Parse Stament between 2 numbers
# 1  
Old 11-10-2008
awk/sed Command: To Parse Stament between 2 numbers

Hi,

I need an awk command that would parse the below expression

Input Format

1 'Stmt1 ............................'2 'Stmt2 ............................'3 'Stmt3 ............................'4 'Stmt4 ............................'5 'Stmt5 ............................'6 'Stmt6 ............................'7 'Stmt7 ............................'8 'Stmt8 ............................'9 'Stmt9 ............................'10 'Stmt10 ............................'11 'Stmt11 ............................'12 'Stmt12 ............................'13 'Stmt13 ............................'

Desired Output

'Stmt1 ............................'
'Stmt2 ............................'
'Stmt3 ............................'
'Stmt4 ............................'
'Stmt5 ............................'
'Stmt6 ............................'
'Stmt7 ............................'
'Stmt8 ............................'
'Stmt9 ............................'
'Stmt10 ............................'
'Stmt11 ............................'
'Stmt12 ............................'
'Stmt13 ............................'

1) It must look for all words between consecutive numbers
2) The statement / expression may contain special characters like $,white space,TAB,colon etc. The command must omit those
3)However the statement will not have any numbers
4) The next number that marks the begin of new statement will be increment the previous by 1
5) Like in the above example all statements may not start with ' character or end with a ....' pattern

Thanks and Best Regards,
Rajan.S
# 2  
Old 11-10-2008
Is this close to what you want ?

Code:
#  cat infile
1 'Stmta ............................'2 'Stmtb ............................'3 'Stmtc ............................'4 'Stmtd ............................'5 'Stmte ............................'6 'Stmtf ............................'7 'Stmtg ............................'8 'Stmth ............................'9 'Stmti ............................'10 'Stmtj ............................'11 'Stmtk ............................'12 'Stmtl ............................'13 'Stmtm ............................'

#   sed 's/[0-9][0-9]*[^0-9]/999/g'  infile | tr -s "9" "\n"

'Stmta ............................'
'Stmtb ............................'
'Stmtc ............................'
'Stmtd ............................'
'Stmte ............................'
'Stmtf ............................'
'Stmtg ............................'
'Stmth ............................'
'Stmti ............................'
'Stmtj ............................'
'Stmtk ............................'
'Stmtl ............................'
'Stmtm ............................'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed/awk script to parse list of bandwidth rules

Hello all gurus, I have a long list of rules as below: 20 name:abc addr:203.45.247.247/255.255.255.255 WDW-THRESH:12 BW-OUT:10000000bps BW-IN:15000000bps STATSDEVICE:test247 STATS:Enabled (4447794/0) <IN OUT> 25 name:xyz160 addr:203.45.233.160/255.255.255.224 STATSDEVICE:test160... (3 Replies)
Discussion started by: sb245
3 Replies

2. Shell Programming and Scripting

Use awk or sed to parse delimited string

Hi I am trying to figure out the best way to search a long log file and print out certain information. For example if I had a line in a log file delimited by ampersand first_name=mike&last_name=smith&zip_code=55555&phone=555-5555&state=ma&city=boston and I only wanted to search for and... (3 Replies)
Discussion started by: mstefaniak
3 Replies

3. Shell Programming and Scripting

parse xm entry with awk/sed

Hi folks, I have XML files with the following sections (section occurs once per file) in them: <AuthorList CompleteYN="Y"> <Author ValidYN="Y"> <LastName>Bernal</LastName> <ForeName>Federico</ForeName> ... (3 Replies)
Discussion started by: euval
3 Replies

4. Shell Programming and Scripting

sed command, look for numbers following letters

If I have a set of strings, C21 F231 H42 1C10 1F113 and I want to isolate the ints following the char, what would the sed string be to find numbers after letters? If I do, *, I will get numbers after letters, but I am looking to do something like, sed 's/*/\t*/g' this will give me... (14 Replies)
Discussion started by: LMHmedchem
14 Replies

5. Shell Programming and Scripting

A mistake in awk command I used to parse numbers

Hi I have a big file with a certain pattern (shown below) from which I need to parse out some digits in tabular format. The format of the file is: '-' indicates text which doesn't to be parsed # Output of huzzle for sequence file 1000.Clade1.html - - - -- -------... (2 Replies)
Discussion started by: Lucky Ali
2 Replies

6. Shell Programming and Scripting

sed or awk to parse this text

I am just beginning with sed and awk and understand that they are "per" line input. That is, they operate on each line individually, and output based on rules, etc. But I have multi-line text blocks that looks as follows, and wish to ONLY extract the text between the first hyphen (-) and the... (13 Replies)
Discussion started by: bulgin
13 Replies

7. Shell Programming and Scripting

sed command to parse Apache config file

Hi there, am trying to parse an Apache 'server' config file. A snippet of the config file is shown below: ..... ProxyPassReverse /foo http://foo.example.com/bar ..... ..... RewriteRule ^/(.*) http://www.example.com/$1 RewriteRule /redirect https://www.example1.com/$1 ........ (7 Replies)
Discussion started by: jy2k7ca
7 Replies

8. Shell Programming and Scripting

awk/sed Command : Parse parameter file / send the lines to the ksh export command

Sorry for the duplicate thread this one is similar to the one in https://www.unix.com/shell-programming-scripting/88132-awk-sed-script-read-values-parameter-files.html#post302255121 Since there were no responses on the parent thread since it got resolved partially i thought to open the new... (4 Replies)
Discussion started by: rajan_san
4 Replies

9. Shell Programming and Scripting

How to parse slash / in sed command..

Hi All, I am trying to replace paths with \ (as in NT) with / (as in Unix) in a script using sed. Following is the command I use: sed "s/e:\Kenny_test\csv_files/var/opt/ciw/data/outbound/g" EMEA4710.SQL > test the string to replace is e:\Kenny_test\csv_files the target string needs to... (3 Replies)
Discussion started by: Abhidey
3 Replies

10. Shell Programming and Scripting

To parse through the file and print output using awk or sed script

suppose if u have a file like that Hen ABCCSGSGSGJJJJK 15 Cock ABCCSGGGSGIJJJL 15 * * * * * * : * * * . * * * : Hen CFCDFCSDFCDERTF 30 Cock CHCDFCSDHCDEGFI 30 * . * * * * * * * : * * :* : : . The output shud be where there is : and . It shud... (4 Replies)
Discussion started by: cdfd123
4 Replies
Login or Register to Ask a Question