![]() |
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 |
| PERL: Searching for a string in a text file problem | meevagh | Shell Programming and Scripting | 15 | 05-01-2008 10:57 AM |
| Searching for text in a Space delimited File | andyblaylock | UNIX for Dummies Questions & Answers | 6 | 11-27-2007 07:33 PM |
| Searching directory for file that contains some text. | LordJezo | UNIX for Dummies Questions & Answers | 4 | 04-04-2006 08:58 PM |
| searching each file in a directory for text | jim majors | Shell Programming and Scripting | 2 | 03-23-2006 08:29 PM |
| Searching for text in files | GandalfWhite | Linux | 2 | 01-21-2004 01:26 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Hello all!
I've been working for days on this and it is really bugging me!! Here's my dilemma: Say I have a very large text file which contains fields delimited my a ':' which logs various records. Each record is separated by a newline character, therefore I can search for lines with 'grep' to find the results i want. The problem is, there may be as many as 30 or so fields with associated values per entry...not an issue...but, if a certain field is not used for a particular record, that field is not included in the file entry (not even a '::' for an empty field...i didn't write the software). So the problem arrises that yes i can search for lines containing whatever i want, but sometimes I don't want to view 30 or so fields, sometimes i am only interested in one or two fields...now some of you may say use something like '# cut -d: -f22,24' or '# awk -F: {print $1, $2}' but, since not every field is used for ever record, certain data does not always appear in the same field!!!! I can guess which field until i get the correct one, but this is often waaaaayyy too time consuming. Is there a way to somehow use a string or expression to delimit a field (as opposed to a character which cut or awk only seem to do)?? Or is there a way to do this with awk?? Thank you so much... Sorry if it was really long winded...i'm flustered!!! |
|
||||
|
I'm using Solaris 9 with the bash shell...
Here's a sample of what the data may look like: # grep 'tid=1234567' /$HOME/somedirectory/somefile :dt=031231130001:ca=50:sq=35:tid=1234567:ul=0542:tk=05:tm=07 :dt=031231130234:ca=23:sq=36:tid=1234567:tk=09:tm=12 :dt=031231130555:ca=99:sq=37:tid=1234567:ul=0425:ty=324:tk=03:tm=03 :dt=031231130925:ca=67:sq=38:tid=1234567:ul=0465:ty=324:uw=0778:tk=02:tm=22 I'd ideally search for any specific results in a particular field (which i can already do), but would like to only print out a certain field to the screen...for example, I'd like to print to the screen only the 'tk' field and value for each line (and not all the other garbage). For each entry above though, it appears in the 6th, 5th, 7th, and then 8th field, which can be different for any entry. If i added a 'cut -d: -f6', i'd only get the 'tk' for the first matching line and all the rest would be other fields... How can I extract only that 'tk' field if it appears in a different place each time? That's why i was wondering if there was a way to use a string or expression as a delimiter rather than a character (like use 'tk' instead of ':' then print the first field, that being 'tk=whatever') Thanks! |
|
||||
|
Ohh, I think I am grasping that...please correct me if i am wrong, that basically means:
print 'tk=', then substitute, starting at the beginning of the line, any character, any # of times up to the value of 'tk', and then the ':' after that value, and any other character any number of times...then replace it all with just the value of 'tk', after the 'tk='? I am still somewhat confused with the notation of the backreference, \(tk=[^:]*\), but pretty much get the rest...I'll try it soon! Thank you Perderabo! |
![]() |
| Bookmarks |
| Tags |
| solaris |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|