![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| printf | mirusnet | Shell Programming and Scripting | 4 | 01-23-2008 10:09 AM |
| AwK printf question | whatisthis | UNIX for Dummies Questions & Answers | 4 | 12-10-2007 01:17 PM |
| printf | arunviswanath | High Level Programming | 2 | 09-19-2007 09:31 PM |
| printf command in ksh | cin2000 | Shell Programming and Scripting | 1 | 12-21-2005 02:48 PM |
| Using printf to center | CSGUY | Shell Programming and Scripting | 2 | 04-19-2005 09:15 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
printf / regex
Morning folks,
I need help with the following issue: Let's say we I have the following output: Code:
First Name: Test Last Name: Test2 Number: T1234 Number2: T1234 Code:
T1234 Now I want to grep/nawk/printf/sed out the Number: - I like to search for T[0-9][0-9][0-9][0-9] - Aditionally the script should just print out one T-Number (needed Output) Can you help me to iplement this requirements into a one liner? Cheers, Domi |
|
||||
|
Thank you guys.
@pludi Your script does not work: Code:
[user@host] ~
# more file
iFirst Name: Test
Last Name: Test2
Number: T1234
Number2: T1234
[user@host] ~
# awk '/T[0-9]{4}/{print $2}' file | uniq
[user@host] ~
i can not use grep -o (I'm running Solaris 10 so I'm using -e instead) Code:
[user@host] ~
# /usr/xpg4/bin/grep -e "T[0-9]\{4\}" file | uniq
Number: T1234
Number2: T1234
[user@host] ~
What is when i have the following output: Code:
First Name: Test Last Name: Test2 Number: asd asdsf 234 T1234 ...dasda Number 2: asd asdsf 234 T1234 ...dasda |
|
||||
|
Code:
Code:
sed -n '/T[0-9]\{4\}/{s/.*\(T[0-9]\{4\}\).*/\1/g;p}' file
Code:
First Name: Test Last Name: Test2 Number: asd asdsf 234 T1234 ...dasda Number 2: asd asdsf 234 T1234 ...dasda Code:
T1234 |
|
||||
|
Hmm...
Code:
[user@host] /
# more file
First Name: Test
Last Name: Test2
Number: asd asdsf 234 T1234 ...dasda
Number 2: asd asdsf 234 T1234 ...dasda
[user@host] /
# sed -n '/T[0-9]\{4\}/{s/.*\(T[0-9]\{4\}\).*/\1/g;p}' file
sed: command garbled: /T[0-9]\{4\}/{s/.*\(T[0-9]\{4\}\).*/\1/g;p}
[user@host] /
#
Thx very much for your help. |
|
||||
|
Quote:
It works for me: Code:
$ cat zzz.txt
First Name: Test
Last Name: Test2
Number: asd asdsf 234T1234 A1...dasda
Number 2: asd asdsf 234 T1234 A1...dasda
awk '{s=match($0, "T[0-9][0-9][0-9][0-9]");if(s){print substr($0,RSTART,RLENGTH + 3 )}}' zzz.txt
T1234 A1
T1234 A1
Quote:
Code:
awk '{s=match($0, "T[0-9][0-9][0-9][0-9]");if(s){print substr($0,RSTART,RLENGTH),"A1"}}' zzz.txt
T1234 A1
T1234 A1
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|