Combine several commands which write their output to different files
Hi all,
I have large files with url-s ending on "|<number>" which is the Page Rank, for example Code:
http://www.machinokairo.com/2012/05/post-39.html|2 Code:
grep --invert-match "|0" sitelist >> sitelist_PR1.txt |
Just ">>" them to the same filename. ">>" means append, whereas ">" means replace.
Or, if for other reasons you want them to remain separate, run the commands then "cat file1 file2 file3 > outputfile" |
Quote:
|
Code:
#!/bin/bash Then tries to grep for the occurance of a bar and that number at the end of each line in the input file and puts them in the output file accordingly. |
Quote:
Code:
|2 |
Combine several commands which write their output to different files
in my example PR is a variable in the "for" loop it is refered to in the main line as ${PR} so first time round the grep command will look for "|0$" where $ tells grep to match it at the end of the line. Next time through the loop it becomes "|1$" etc.
|
the script creates only empty files
|
Combine several commands which write their output to different files
worked fine for me when I created an input file in the firnat you gave.
|
Quote:
anyway, thanks for your efforts and time. |
TenTenth's grep expression is bit stricter than the original. I can think of a couple of cases where this could cause failure:
Does "sitefile" use DOS/Windows line endings (post output of file sitefile)? Can the page rank be more than one digit? |
Quote:
The point is that script gives me output in a different way than desired i.e. each output file contains only url-s with PR from its name sitelist_PR1.txt contains only url-s with PR1. |
Untested:
Code:
awk -F\| '{for (i=1; i <= 5; i++) { if ($2 >= i) print > ("sitelist_PR" i ".txt") }}' sitelist |
Quote:
Code:
awk: cmd. line:1: {for (i=1; i <= 5; i++) { if ($2 >= i) print > ("sitelist_PR" i ".txt") } |
Ah, missed the closing brace (fixed in edit).
|
Quote:
|
All times are GMT -5. The time now is 03:54 PM. |