![]() |
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 |
| Multiple search string in multiple files using awk | pinnacle | Shell Programming and Scripting | 0 | 05-05-2009 01:08 PM |
| PERL: add string to multiple lines | bonny | Shell Programming and Scripting | 4 | 05-19-2008 12:11 PM |
| last occurrence of a string across multiple files | porphyrin | UNIX for Dummies Questions & Answers | 2 | 12-24-2007 09:39 AM |
| String replacement in multiple files | WABonnett | Shell Programming and Scripting | 2 | 02-17-2004 03:49 PM |
| Editing one string in multiple files | Skoshi | UNIX for Dummies Questions & Answers | 1 | 11-10-2001 02:13 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Hi all,
I am newbie in unix. Just have some doubts on how to join multiple lines into single line. I have 1 file with following contents. R96087641 HostName-kul480My This is no use any more %% E78343970 LocalPath-/app/usr/SG (Blank in this line) %% E73615740 LocalPath-/app/usr/US Urgent Needed %% ..... ..... ..... ..... Each grouping is separated by %%. There are basically 2 kinds of grouping which is HostName and LocalPath. I need to format the content into 2 separate files differentiate by HostName and LocalPath. In the files, the keyword HostName and LocalPath must be removed. Below is the sample of formatted data. (HostName.txt) R96087641|kul480My|This is no use any more ..... ..... (LocalPath.txt) E78343970|/app/usr/SG| E73615740|/app/usr/US|Urgent Needed ..... ..... I have really no idea on how to sort it out. My knowledge on awk also not strong enough to make it. Hopes someone could help to solve my problem. Thanks. Last edited by whchee; 05-08-2009 at 12:28 PM.. |
|
||||
|
Hi Vgersh,
The logic seems working by reading it, neat and understandable. However, i can only test it on Monday. Will let you know the result then. Btw, if i keen on using awk only, will there be lot diff with nawk? I am not so sure is nawk working in HP-UX environment not... Kindly advice. |
|
||||
|
Code:
$/="%%\n";
open FH1,"+>HostName.txt";
open FH2,"+>LocalPath.txt";
while(<DATA>){
my @tmp=split("\n",$_);
my @t1=split("-",$tmp[1]);
$tmp[1]=~s/.*-//;
my $str=join "|",@tmp[0..2];
if($t1[0] eq "HostName"){
print FH1 $str."\n";
}
else{
print FH2 $str."\n";
}
}
__END__
R96087641
HostName-kul480My
This is no use any more
%%
E78343970
LocalPath-/app/usr/SG
(Blank in this line)
%%
E73615740
LocalPath-/app/usr/US
Urgent Needed
%%
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|