|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Command line explanation...
Hi, can anybody explain this command line to me in detail?
The command line is showed as below : perl -e ' $col1=1; $col2=0; ($f1,$f2)=@ARGV; open(F2,$f2); while (<F2>) { s/\r?\n//; @F=split /\t/, $_; $line2{$F[$col2]} .= "$_\n" }; $count2 = $.; open(F1,$f1); while (<F1>) { s/\r?\n//; @F=split /\t/, $_; $x = $line2{$F[$col1]}; if ($x) { $num_changes = ($x =~ s/^/$_\t/gm); print $x; $merged += $num_changes } } warn "\nJoining $f1 column $col1 with $f2 column $col2\n$f1: $. lines\n$f2: $count2 lines\nMerged file: $merged lines\n"; ' file1 file2 > mergefile1&2 |
|
#2
|
|||
|
|||
|
firstly, do you have Perl experience? If not, i suggest you start reading up. things like $col=1 is very easy to understand.
secondly, organize the code into different lines, put them in a script and put them in code tags. cramming up perl code in one line like this is poor practice.
__________________
Python tutorial |Learn Bash scripting|Perl documentation|UNIX shell scripting resource|Awk and why|File Renamer |
|
#3
|
|||
|
|||
|
Quote:
Hi, actually I just start learn perl. Thus don't have the experience and enough knowledge to modify the perl provided to get my desired output result. The command line is at the script showed as below: perl -e ' $col1=1; $col2=0; ($f1,$f2)=@ARGV; open(F2,$f2); while (<F2>) { s/\r?\n//; @F=split /\t/, $_; $line2{$F[$col2]} .= "$_\n" }; $count2 = $.; open(F1,$f1); while (<F1>) { s/\r?\n//; @F=split /\t/, $_; $x = $line2{$F[$col1]}; if ($x) { $num_changes = ($x =~ s/^/$_\t/gm); print $x; $merged += $num_changes } } warn "\nJoining $f1 column $col1 with $f2 column $col2\n$f1: $. lines\n$f2: $count2 lines\nMerged file: $merged lines\n"; ' You got any better suggestion or command line can get my desired output result? Thanks a lot for your help and explanation ![]() |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Command line explanation... |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|