![]() |
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 |
| read and drop files | shantanuo | UNIX for Dummies Questions & Answers | 1 | 09-26-2008 03:00 AM |
| Drop a Column from a File | Raamc | UNIX for Dummies Questions & Answers | 4 | 01-09-2008 10:36 AM |
| Dynamic Drop down boxes | garric | Shell Programming and Scripting | 13 | 10-18-2007 11:54 AM |
| Drop records with non-numerics in field X | akxeman | Shell Programming and Scripting | 3 | 08-15-2007 12:55 AM |
| Drop Users | trfrye | UNIX for Dummies Questions & Answers | 2 | 08-31-2005 03:39 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Quote:
I've asked the development team that works on the program to add keyword search to the reports we can generate from the command line, but even if they do it, it'll take over a year to get it in place. The government moves extremely slow when tinkering with stuff they consider "operational" to the National Airspace System, even when it doesn't have any effect on controlling aircraft! ![]() Thanks again for the suggestions. I'll keep tinkering, but scripting isn't my strong point. I can program in Visual Basic, but that won't work on Linux ![]() |
|
||||
|
Quote:
![]() |
|
||||
|
If you can play with the input file a little, I can do this in ksh.
Code:
#!/bin/ksh FILE1=$1 FILE2=tmp.txt cat $FILE1 | tr -s '\012' ' ' > $FILE2 print >> $FILE2 cat $FILE2 | sed 's/ \([0-2][0-9][0-5][0-9] TMU\)/\ \1/g' | sed -n '/[0-2][0-9][0-5][0-9] TMU [MW][EX]/P' rm $FILE2 thisscript.sh 15.txt Notes: I'm commenting here to keep the clutter in the code down. Script takes your input file as parameter '1' and asigns that to FILE1. FILE2 is a temp file we'll use for output. cat FILE1 to 'tr' to change all newlines to spaces and store the result in FILE2 'print' then appends a newline to the end of FILE2. This is necessary or 'sed' will ignore the input of FILE2 as it must see a newline. cat FILE2 into two distinct sed process. The first inserts a new line before the specified pattern of ' #### TMU' (I use # instead of the actual numerical pattern for brevity here). Note there is a space before the first number. In the first sed process note that there is a REQUIRED newline after the '/\' so that the rest of the command resumes on the next line with "\1/g' " Now you have records that are separated by a newline w/o any newlines in the records themselves as there was before. So the second sed process can now identify each record you want printed with only 1 address, and print the full record, w/o printing the record(s) you don't want. The [WM][EX] will, unfortunately find 'MX' and 'WE' as well as 'WX' and 'ME', so you may have to play with this depending upon your actual data. Last edited by vgersh99; 01-22-2009 at 01:55 PM.. Reason: fixed code tags |
|
||||
|
Quote:
Also, thanks for fixing my code tags before. I was trying to do that, and then saw it was already done. So the 'tr' line can be changed to: Code:
tr -s '\012' ' ' < $FILE1 > $FILE2 Code:
sed -e 's/ \([0-2][0-9][0-5][0-9] TMU\)/\ \1/g' $FILE2 | sed -n -e '/[0-2][0-9][0-5][0-9] TMU [MW][EX]/P' |
|
||||
|
I don't want anyone to think I'm ignoring posts, but I got pulled into an all-day meeting and it may last through tomorrow. Next week I'm traveling (Hawaii, yeah!) so won't be able to test anything on a Linux box. I will still try things on my Windows laptop, but as I've already found, what works here may not work there.
![]() I really appreciate all the help, and I'm sure we'll come up with a solution. I'm excited to try using awk instead of sed, and I have it on my laptop as well. Please keep the suggestions coming! |
![]() |
| Bookmarks |
| Tags |
| awk, awk trim, trim, trim awk |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|