If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Deleting Fields

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-01-06, 00:54
maria01 maria01 is offline
Registered User
 
Join Date: Feb 2006
Posts: 2
Deleting Fields

File Layout:

rtg1ad00620041230tom 12 ^m
rtg2ad00620041230mark15^m
rtg1bd00620041231mari10 ^m
rtg2bd00620041231sam 12^m

Questions:
1) what command can i use to strip the spaces from position 23 - ^m in line record "rtg1" (sed???)

2) after that, delete the first 17 chars in record "rtg2" and than concat line "rtg1" with "rtg2" to make one record

Results
rtg1ad00620041230tom 12mark15^m
rtg1bd00620041231mari10 12^m

Appreciate the help.
Mary
Reply With Quote
  #2 (permalink)  
Old 02-01-06, 12:03
hyperbole hyperbole is offline
Registered User
 
Join Date: Jan 2006
Posts: 32
You can do all that in sed or awk.

Are all the lines labeled rtg1 or rtg2 and nothing else? Are the rtg1 and rtg2 lines always in that order or can they be in any order?

I'll make the following assumptions:
1) this is a large file with repeated rtg1 and rtg2 lines.
2) the file only contains lines starting with rtg1 or rtg2.
3) the lines always appear in the order rtg1, rtg2. Although not necessarily consecutively.
4) '^m' means end of line
5) the key following rtg1 is unique for each set of lines and is always 13 characters long.

create a file called script.awk containing:
Code:
/rtg1/ { part1 = substr($0, 1,23);
           part2 = substr($0, 24); 
           gsub(/ /, "", part2);
           line = sprintf("%s%s", part1, part2);
           key = substr($0, 5,13);
           save[key] = line;
         }
/rtg2/ { key = substr($0, 5,13);
           if  (length(save[key]) == 0)
              printf("Error: no rtg1 line found for %s\n", $0);
           else
              printf("%s%s\n", save[key], substr($0, 18));
         }
then run the following from the command line:
# awk -f script.awk file-you-want-to-process > result-file



.
Reply With Quote
  #3 (permalink)  
Old 02-01-06, 22:09
maria01 maria01 is offline
Registered User
 
Join Date: Feb 2006
Posts: 2
Thank you.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On