question regarding awk and regular exp?

I have a text file as follows;

1256-5656    josh; barry
dd-<55> test
4566-7777 james;john
ss-kkk test_2
4566
7777-9999 sean;penn
dd<66> test_3

I would like to write a awk script that matches the pattern four numbers a dash and four numbers (eg; 1256-5656) and pring the fields in that record. I tried doing the following but it does not work;

awk '$1~/^\d{4}-\d{4}/{print $1, $2, $3, $4}' filename.txt.

Also, how can I print the fields in the record below the matched pattern. For eg I would like to print;

dd-<55>  test
ss-kkk     test_2


Thanks for the help.

A
aej1973Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
awk '/^[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9]/'  filename.txt.
0
aej1973Author Commented:
Thanks. What about being able to print the next line?

A
0
ozoCommented:
awk '!--n
/^[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9]/{n=1;print}' filename.txt
0
OWASP: Forgery and Phishing

Learn the techniques to avoid forgery and phishing attacks and the types of attacks an application or network may face.

aej1973Author Commented:
it is not working. The error I am getting is as follows;

awk '!--n'/^[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9]/'{n=1; print $1,"|", $2,"|",$11,"|", $13}' FULL.TXT
awk: cmd. line:1: !--n/^[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9]/{n=1; print $1,"|", $2,"|",$11,"|", $13}
awk: cmd. line:1:      ^ syntax error
awk: cmd. line:1: !--n/^[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9]/{n=1; print $1,"|", $2,"|",$11,"|", $13}
awk: cmd. line:1:           ^ syntax error
awk: cmd. line:1: !--n/^[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9]/{n=1; print $1,"|", $2,"|",$11,"|", $13}
awk: cmd. line:1:                ^ syntax error
awk: cmd. line:1: !--n/^[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9]/{n=1; print $1,"|", $2,"|",$11,"|", $13}
awk: cmd. line:1:                     ^ syntax error
awk: cmd. line:1: !--n/^[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9]/{n=1; print $1,"|", $2,"|",$11,"|", $13}
awk: cmd. line:1:                          ^ syntax error
awk: cmd. line:1: !--n/^[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9]/{n=1; print $1,"|", $2,"|",$11,"|", $13}
awk: cmd. line:1:                                ^ syntax error
awk: cmd. line:1: !--n/^[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9]/{n=1; print $1,"|", $2,"|",$11,"|", $13}
awk: cmd. line:1:                                     ^ syntax error
awk: cmd. line:1: !--n/^[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9]/{n=1; print $1,"|", $2,"|",$11,"|", $13}
awk: cmd. line:1:                                          ^ syntax error
awk: cmd. line:1: !--n/^[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9]/{n=1; print $1,"|", $2,"|",$11,"|", $13}
awk: cmd. line:1:                                            ^ unterminated regexp
0
ozoCommented:
awk '!--n
/^[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9]/{n=1; print $1,"|", $2,"|",$11,"|", $13}' FULL.TXT
0
aej1973Author Commented:
This is prining line 1 and 2, but I need only line 2 to be printed. Thanks for the help.

A
0
ozoCommented:
awk '!--n{ print $1,"|", $2,"|",$11,"|", $13}
/^[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9]/{n=1}'  FULL.TXT
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
aej1973Author Commented:
Thank you very much.
0
aej1973Author Commented:
If you do not mind can I ask you one more doubt? How can I have the output in such a way that the output has the first field in the first record and the 3rd and 4th fields of the 2 second record on one line in the output? for eg I would like my output to be

1256-5656  dd-<55> test
4566-7777 ss-kkk test_2

Thanks for the help.

A

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.