标签云

微信群

扫码加入我们

WeChat QR Code

I have many huge files in say 3 different folders from which i would like to copy say lines from X to Y of files of the same name and append them into a new file of the same name. I tried doing ls seed1/* | while read FILE; dohead -n $Y| tail -n $X seed1/$FILE seed2/$FILE seed3/$FILE> combined/$FILEdoneThis does the job for the first value of $FILE, but this does not return the prompt, and hence I am unable to execute this loop.For example i have the following files in three different folders, seed1, seed2 and seed3:seed1/foo.datseed1/bar.datseed1/qax.datseed2/foo.datseed2/bar.datseed2/qax.datseed3/foo.datseed3/bar.datseed3/qax.datI would like to combine lines 10 to 20 of all files in to a combined folder:combined/foo.datcombined/bar.datcombined/qax.datEach of the files in combined have 30 lines, with 10 each from seed1,seed2 and seed3.


The prompt disappears because you have not given 'head' a file argument. Using ls to generate FILE and then overwriting FILE looks very fishy as well.

2019年04月19日55分26秒

sorry, my question was unclear.. can you edit your answer to accommodate this question (I have edited it)?

2019年04月20日55分26秒

Edit your question to clarify what you are trying to do as we can't tell from a script that DOESN'T do what you want what it is you actually want (clearly since we already tried that and apparently guessed wrong). Include concise, testable sample input and expected output.

2019年04月20日55分26秒

I guess for f in seed1/*; do b=${f#seed1/}; awk -v x="$x" -v y="$y" 'FNR >=x; FNR==y{nextfile}' "$f" "seed2/$b" "seed3/$b" >"combined/$b"; done

2019年04月20日55分26秒

I updated my answer.

2019年04月20日55分26秒