I am making files numbered 1-1000. I need to have the files printed out such that the first one is 0000.txt, the second 0001.txt, and the hundredth and first will be 0100.txt, etc.
What command would accomplish the same thing as the printf format %04d in c?
Edit: I'm running everything on Mac OSX, and using bash in terminal. Too be fair I have no idea what POSIX is, or even what a shell is. Sorry I didn't specify my system earlier.
Use printf, just like in C. It's available in any POSIXly Bourne Shell (zsh, ksh, bash, ...)
$ FILE=$(printf %04d 42).txt
$ echo "$FILE"
0042.txt
You can try something like this:
for i in $(seq -w 0 1000); do
touch "$i".txt;
done
Test:
$ mkdir test
$ cd test
$ ls
$ for i in $(seq -w 0 1000); do
> touch "$i".txt;
> done
$ ls
0000.txt 0044.txt 0088.txt 0132.txt 0176.txt 0220.txt 0264.txt 0308.txt 0352.txt 0396.txt 0440.txt 0484.txt 0528.txt 0572.txt 0616.txt 0660.txt 0704.txt 0748.txt 0792.txt 0836.txt 0880.txt 0924.txt 0968.txt
0001.txt 0045.txt 0089.txt 0133.txt 0177.txt 0221.txt 0265.txt 0309.txt 0353.txt 0397.txt 0441.txt 0485.txt 0529.txt 0573.txt 0617.txt 0661.txt 0705.txt 0749.txt 0793.txt 0837.txt 0881.txt 0925.txt 0969.txt
0002.txt 0046.txt 0090.txt 0134.txt 0178.txt 0222.txt 0266.txt 0310.txt 0354.txt 0398.txt 0442.txt 0486.txt 0530.txt 0574.txt 0618.txt 0662.txt 0706.txt 0750.txt 0794.txt 0838.txt 0882.txt 0926.txt 0970.txt
0003.txt 0047.txt 0091.txt 0135.txt 0179.txt 0223.txt 0267.txt 0311.txt 0355.txt 0399.txt 0443.txt 0487.txt 0531.txt 0575.txt 0619.txt 0663.txt 0707.txt 0751.txt 0795.txt 0839.txt 0883.txt 0927.txt 0971.txt
0004.txt 0048.txt 0092.txt 0136.txt 0180.txt 0224.txt 0268.txt 0312.txt 0356.txt 0400.txt 0444.txt 0488.txt 0532.txt 0576.txt 0620.txt 0664.txt 0708.txt 0752.txt 0796.txt 0840.txt 0884.txt 0928.txt 0972.txt
0005.txt 0049.txt 0093.txt 0137.txt 0181.txt 0225.txt 0269.txt 0313.txt 0357.txt 0401.txt 0445.txt 0489.txt 0533.txt 0577.txt 0621.txt 0665.txt 0709.txt 0753.txt 0797.txt 0841.txt 0885.txt 0929.txt 0973.txt
0006.txt 0050.txt 0094.txt 0138.txt 0182.txt 0226.txt 0270.txt 0314.txt 0358.txt 0402.txt 0446.txt 0490.txt 0534.txt 0578.txt 0622.txt 0666.txt 0710.txt 0754.txt 0798.txt 0842.txt 0886.txt 0930.txt 0974.txt
0007.txt 0051.txt 0095.txt 0139.txt 0183.txt 0227.txt 0271.txt 0315.txt 0359.txt 0403.txt 0447.txt 0491.txt 0535.txt 0579.txt 0623.txt 0667.txt 0711.txt 0755.txt 0799.txt 0843.txt 0887.txt 0931.txt 0975.txt
0008.txt 0052.txt 0096.txt 0140.txt 0184.txt 0228.txt 0272.txt 0316.txt 0360.txt 0404.txt 0448.txt 0492.txt 0536.txt 0580.txt 0624.txt 0668.txt 0712.txt 0756.txt 0800.txt 0844.txt 0888.txt 0932.txt 0976.txt
0009.txt 0053.txt 0097.txt 0141.txt 0185.txt 0229.txt 0273.txt 0317.txt 0361.txt 0405.txt 0449.txt 0493.txt 0537.txt 0581.txt 0625.txt 0669.txt 0713.txt 0757.txt 0801.txt 0845.txt 0889.txt 0933.txt 0977.txt
0010.txt 0054.txt 0098.txt 0142.txt 0186.txt 0230.txt 0274.txt 0318.txt 0362.txt 0406.txt 0450.txt 0494.txt 0538.txt 0582.txt 0626.txt 0670.txt 0714.txt 0758.txt 0802.txt 0846.txt 0890.txt 0934.txt 0978.txt
0011.txt 0055.txt 0099.txt 0143.txt 0187.txt 0231.txt 0275.txt 0319.txt 0363.txt 0407.txt 0451.txt 0495.txt 0539.txt 0583.txt 0627.txt 0671.txt 0715.txt 0759.txt 0803.txt 0847.txt 0891.txt 0935.txt 0979.txt
0012.txt 0056.txt 0100.txt 0144.txt 0188.txt 0232.txt 0276.txt 0320.txt 0364.txt 0408.txt 0452.txt 0496.txt 0540.txt 0584.txt 0628.txt 0672.txt 0716.txt 0760.txt 0804.txt 0848.txt 0892.txt 0936.txt 0980.txt
0013.txt 0057.txt 0101.txt 0145.txt 0189.txt 0233.txt 0277.txt 0321.txt 0365.txt 0409.txt 0453.txt 0497.txt 0541.txt 0585.txt 0629.txt 0673.txt 0717.txt 0761.txt 0805.txt 0849.txt 0893.txt 0937.txt 0981.txt
0014.txt 0058.txt 0102.txt 0146.txt 0190.txt 0234.txt 0278.txt 0322.txt 0366.txt 0410.txt 0454.txt 0498.txt 0542.txt 0586.txt 0630.txt 0674.txt 0718.txt 0762.txt 0806.txt 0850.txt 0894.txt 0938.txt 0982.txt
0015.txt 0059.txt 0103.txt 0147.txt 0191.txt 0235.txt 0279.txt 0323.txt 0367.txt 0411.txt 0455.txt 0499.txt 0543.txt 0587.txt 0631.txt 0675.txt 0719.txt 0763.txt 0807.txt 0851.txt 0895.txt 0939.txt 0983.txt
0016.txt 0060.txt 0104.txt 0148.txt 0192.txt 0236.txt 0280.txt 0324.txt 0368.txt 0412.txt 0456.txt 0500.txt 0544.txt 0588.txt 0632.txt 0676.txt 0720.txt 0764.txt 0808.txt 0852.txt 0896.txt 0940.txt 0984.txt
0017.txt 0061.txt 0105.txt 0149.txt 0193.txt 0237.txt 0281.txt 0325.txt 0369.txt 0413.txt 0457.txt 0501.txt 0545.txt 0589.txt 0633.txt 0677.txt 0721.txt 0765.txt 0809.txt 0853.txt 0897.txt 0941.txt 0985.txt
0018.txt 0062.txt 0106.txt 0150.txt 0194.txt 0238.txt 0282.txt 0326.txt 0370.txt 0414.txt 0458.txt 0502.txt 0546.txt 0590.txt 0634.txt 0678.txt 0722.txt 0766.txt 0810.txt 0854.txt 0898.txt 0942.txt 0986.txt
0019.txt 0063.txt 0107.txt 0151.txt 0195.txt 0239.txt 0283.txt 0327.txt 0371.txt 0415.txt 0459.txt 0503.txt 0547.txt 0591.txt 0635.txt 0679.txt 0723.txt 0767.txt 0811.txt 0855.txt 0899.txt 0943.txt 0987.txt
0020.txt 0064.txt 0108.txt 0152.txt 0196.txt 0240.txt 0284.txt 0328.txt 0372.txt 0416.txt 0460.txt 0504.txt 0548.txt 0592.txt 0636.txt 0680.txt 0724.txt 0768.txt 0812.txt 0856.txt 0900.txt 0944.txt 0988.txt
0021.txt 0065.txt 0109.txt 0153.txt 0197.txt 0241.txt 0285.txt 0329.txt 0373.txt 0417.txt 0461.txt 0505.txt 0549.txt 0593.txt 0637.txt 0681.txt 0725.txt 0769.txt 0813.txt 0857.txt 0901.txt 0945.txt 0989.txt
0022.txt 0066.txt 0110.txt 0154.txt 0198.txt 0242.txt 0286.txt 0330.txt 0374.txt 0418.txt 0462.txt 0506.txt 0550.txt 0594.txt 0638.txt 0682.txt 0726.txt 0770.txt 0814.txt 0858.txt 0902.txt 0946.txt 0990.txt
0023.txt 0067.txt 0111.txt 0155.txt 0199.txt 0243.txt 0287.txt 0331.txt 0375.txt 0419.txt 0463.txt 0507.txt 0551.txt 0595.txt 0639.txt 0683.txt 0727.txt 0771.txt 0815.txt 0859.txt 0903.txt 0947.txt 0991.txt
0024.txt 0068.txt 0112.txt 0156.txt 0200.txt 0244.txt 0288.txt 0332.txt 0376.txt 0420.txt 0464.txt 0508.txt 0552.txt 0596.txt 0640.txt 0684.txt 0728.txt 0772.txt 0816.txt 0860.txt 0904.txt 0948.txt 0992.txt
0025.txt 0069.txt 0113.txt 0157.txt 0201.txt 0245.txt 0289.txt 0333.txt 0377.txt 0421.txt 0465.txt 0509.txt 0553.txt 0597.txt 0641.txt 0685.txt 0729.txt 0773.txt 0817.txt 0861.txt 0905.txt 0949.txt 0993.txt
0026.txt 0070.txt 0114.txt 0158.txt 0202.txt 0246.txt 0290.txt 0334.txt 0378.txt 0422.txt 0466.txt 0510.txt 0554.txt 0598.txt 0642.txt 0686.txt 0730.txt 0774.txt 0818.txt 0862.txt 0906.txt 0950.txt 0994.txt
0027.txt 0071.txt 0115.txt 0159.txt 0203.txt 0247.txt 0291.txt 0335.txt 0379.txt 0423.txt 0467.txt 0511.txt 0555.txt 0599.txt 0643.txt 0687.txt 0731.txt 0775.txt 0819.txt 0863.txt 0907.txt 0951.txt 0995.txt
0028.txt 0072.txt 0116.txt 0160.txt 0204.txt 0248.txt 0292.txt 0336.txt 0380.txt 0424.txt 0468.txt 0512.txt 0556.txt 0600.txt 0644.txt 0688.txt 0732.txt 0776.txt 0820.txt 0864.txt 0908.txt 0952.txt 0996.txt
0029.txt 0073.txt 0117.txt 0161.txt 0205.txt 0249.txt 0293.txt 0337.txt 0381.txt 0425.txt 0469.txt 0513.txt 0557.txt 0601.txt 0645.txt 0689.txt 0733.txt 0777.txt 0821.txt 0865.txt 0909.txt 0953.txt 0997.txt
0030.txt 0074.txt 0118.txt 0162.txt 0206.txt 0250.txt 0294.txt 0338.txt 0382.txt 0426.txt 0470.txt 0514.txt 0558.txt 0602.txt 0646.txt 0690.txt 0734.txt 0778.txt 0822.txt 0866.txt 0910.txt 0954.txt 0998.txt
0031.txt 0075.txt 0119.txt 0163.txt 0207.txt 0251.txt 0295.txt 0339.txt 0383.txt 0427.txt 0471.txt 0515.txt 0559.txt 0603.txt 0647.txt 0691.txt 0735.txt 0779.txt 0823.txt 0867.txt 0911.txt 0955.txt 0999.txt
0032.txt 0076.txt 0120.txt 0164.txt 0208.txt 0252.txt 0296.txt 0340.txt 0384.txt 0428.txt 0472.txt 0516.txt 0560.txt 0604.txt 0648.txt 0692.txt 0736.txt 0780.txt 0824.txt 0868.txt 0912.txt 0956.txt 1000.txt
0033.txt 0077.txt 0121.txt 0165.txt 0209.txt 0253.txt 0297.txt 0341.txt 0385.txt 0429.txt 0473.txt 0517.txt 0561.txt 0605.txt 0649.txt 0693.txt 0737.txt 0781.txt 0825.txt 0869.txt 0913.txt 0957.txt
0034.txt 0078.txt 0122.txt 0166.txt 0210.txt 0254.txt 0298.txt 0342.txt 0386.txt 0430.txt 0474.txt 0518.txt 0562.txt 0606.txt 0650.txt 0694.txt 0738.txt 0782.txt 0826.txt 0870.txt 0914.txt 0958.txt
0035.txt 0079.txt 0123.txt 0167.txt 0211.txt 0255.txt 0299.txt 0343.txt 0387.txt 0431.txt 0475.txt 0519.txt 0563.txt 0607.txt 0651.txt 0695.txt 0739.txt 0783.txt 0827.txt 0871.txt 0915.txt 0959.txt
0036.txt 0080.txt 0124.txt 0168.txt 0212.txt 0256.txt 0300.txt 0344.txt 0388.txt 0432.txt 0476.txt 0520.txt 0564.txt 0608.txt 0652.txt 0696.txt 0740.txt 0784.txt 0828.txt 0872.txt 0916.txt 0960.txt
0037.txt 0081.txt 0125.txt 0169.txt 0213.txt 0257.txt 0301.txt 0345.txt 0389.txt 0433.txt 0477.txt 0521.txt 0565.txt 0609.txt 0653.txt 0697.txt 0741.txt 0785.txt 0829.txt 0873.txt 0917.txt 0961.txt
0038.txt 0082.txt 0126.txt 0170.txt 0214.txt 0258.txt 0302.txt 0346.txt 0390.txt 0434.txt 0478.txt 0522.txt 0566.txt 0610.txt 0654.txt 0698.txt 0742.txt 0786.txt 0830.txt 0874.txt 0918.txt 0962.txt
0039.txt 0083.txt 0127.txt 0171.txt 0215.txt 0259.txt 0303.txt 0347.txt 0391.txt 0435.txt 0479.txt 0523.txt 0567.txt 0611.txt 0655.txt 0699.txt 0743.txt 0787.txt 0831.txt 0875.txt 0919.txt 0963.txt
0040.txt 0084.txt 0128.txt 0172.txt 0216.txt 0260.txt 0304.txt 0348.txt 0392.txt 0436.txt 0480.txt 0524.txt 0568.txt 0612.txt 0656.txt 0700.txt 0744.txt 0788.txt 0832.txt 0876.txt 0920.txt 0964.txt
0041.txt 0085.txt 0129.txt 0173.txt 0217.txt 0261.txt 0305.txt 0349.txt 0393.txt 0437.txt 0481.txt 0525.txt 0569.txt 0613.txt 0657.txt 0701.txt 0745.txt 0789.txt 0833.txt 0877.txt 0921.txt 0965.txt
0042.txt 0086.txt 0130.txt 0174.txt 0218.txt 0262.txt 0306.txt 0350.txt 0394.txt 0438.txt 0482.txt 0526.txt 0570.txt 0614.txt 0658.txt 0702.txt 0746.txt 0790.txt 0834.txt 0878.txt 0922.txt 0966.txt
Related
Currently trying to preprocess data and need to name all the image files in my folder sequentially, however when I try to do it with the code below, it ends up producing more files that appear to be previous transformations of the images (previously inverted/cropped copies)
ls | cat -n | while read n f; do mv "$f" "$n.png"; done
I wanted the folders in my file to just label the data sequentially and not create any additional files.
The modifications to the image were made using imagemagick on Linux
The output of ls is as below:
000001560000.png~ 000001900000.png~~~~ 000002260000.png~
000001560000.png~~ 000001900000.png~~~~~ 000002260000.png~~
000001560000.png~~~ 000001910000.png~ 000002260000.png~~~
000001560000.png~~~~ 000001910000.png~~ 000002260000.png~~~~
000001560000.png~~~~~ 000001910000.png~~~ 000002260000.png~~~~~
000001570000.png~ 000001910000.png~~~~ 000002270000.png~
000001570000.png~~ 000001910000.png~~~~~ 000002270000.png~~
000001570000.png~~~ 000001920000.png~ 000002270000.png~~~
000001570000.png~~~~ 000001920000.png~~ 000002270000.png~~~~
000001570000.png~~~~~ 000001920000.png~~~ 000002270000.png~~~~~
000001580000.png~ 000001920000.png~~~~ 000002280000.png~
000001580000.png~~ 000001920000.png~~~~~ 000002280000.png~~
000001580000.png~~~ 000001930000.png~ 000002280000.png~~~
000001580000.png~~~~ 000001930000.png~~ 000002280000.png~~~~
000001580000.png~~~~~ 000001930000.png~~~ 000002280000.png~~~~~
000001590000.png~ 000001930000.png~~~~ 000002290000.png~
000001590000.png~~ 000001930000.png~~~~~ 000002290000.png~~
000001590000.png~~~ 000001940000.png~ 000002290000.png~~~
000001590000.png~~~~ 000001940000.png~~ 000002290000.png~~~~
000001590000.png~~~~~ 000001940000.png~~~ 000002290000.png~~~~~
000001600000.png~ 000001940000.png~~~~ 000002300000.png~
000001600000.png~~ 000001940000.png~~~~~ 000002300000.png~~
000001600000.png~~~ 000001950000.png~ 000002300000.png~~~
000001600000.png~~~~ 000001950000.png~~ 000002300000.png~~~~
000001600000.png~~~~~ 000001950000.png~~~ 000002300000.png~~~~~
000001610000.png~ 000001950000.png~~~~ 000002310000.png~
000001610000.png~~ 000001950000.png~~~~~ 000002310000.png~~
000001610000.png~~~ 000001960000.png~ 000002310000.png~~~
000001610000.png~~~~ 000001960000.png~~ 000002310000.png~~~~
000001610000.png~~~~~ 000001960000.png~~~ 000002310000.png~~~~~
000001620000.png~ 000001960000.png~~~~ 000002320000.png~
000001620000.png~~ 000001960000.png~~~~~ 000002320000.png~~
000001620000.png~~~ 000001970000.png~ 000002320000.png~~~
000001620000.png~~~~ 000001970000.png~~ 000002320000.png~~~~
000001620000.png~~~~~ 000001970000.png~~~ 000002320000.png~~~~~
000001630000.png~ 000001970000.png~~~~ 000002330000.png~
000001630000.png~~ 000001970000.png~~~~~ 000002330000.png~~
000001630000.png~~~ 000001980000.png~ 000002330000.png~~~
000001630000.png~~~~ 000001980000.png~~ 000002330000.png~~~~
000001630000.png~~~~~ 000001980000.png~~~ 000002330000.png~~~~~
000001640000.png~ 000001980000.png~~~~ 000002340000.png~
000001640000.png~~ 000001980000.png~~~~~ 000002340000.png~~
000001640000.png~~~ 000001990000.png~ 000002340000.png~~~
000001640000.png~~~~ 000001990000.png~~ 000002340000.png~~~~
000001640000.png~~~~~ 000001990000.png~~~ 000002340000.png~~~~~
000001650000.png~ 000001990000.png~~~~ 000002350000.png~
000001650000.png~~ 000001990000.png~~~~~ 000002350000.png~~
000001650000.png~~~ 000002000000.png~ 000002350000.png~~~
000001650000.png~~~~ 000002000000.png~~ 000002350000.png~~~~
000001650000.png~~~~~ 000002000000.png~~~ 000002350000.png~~~~~
000001660000.png~ 000002000000.png~~~~ 000002360000.png~
000001660000.png~~ 000002000000.png~~~~~ 000002360000.png~~
000001660000.png~~~ 000002010000.png~ 000002360000.png~~~
000001660000.png~~~~ 000002010000.png~~ 000002360000.png~~~~
000001660000.png~~~~~ 000002010000.png~~~ 000002360000.png~~~~~
000001670000.png~ 000002010000.png~~~~ 000002370000.png~
000001670000.png~~ 000002010000.png~~~~~ 000002370000.png~~
000001670000.png~~~ 000002020000.png~ 000002370000.png~~~
000001670000.png~~~~ 000002020000.png~~ 000002370000.png~~~~
000001670000.png~~~~~ 000002020000.png~~~ 000002370000.png~~~~~
000001680000.png~ 000002020000.png~~~~ 000002380000.png~
000001680000.png~~ 000002020000.png~~~~~ 000002380000.png~~
000001680000.png~~~ 000002030000.png~ 000002380000.png~~~
000001680000.png~~~~ 000002030000.png~~ 000002380000.png~~~~
000001680000.png~~~~~ 000002030000.png~~~ 000002380000.png~~~~~
000001690000.png~ 000002030000.png~~~~ 000002390000.png~
000001690000.png~~ 000002030000.png~~~~~ 000002390000.png~~
000001690000.png~~~ 000002040000.png~ 000002390000.png~~~
000001690000.png~~~~ 000002040000.png~~ 000002390000.png~~~~
000001690000.png~~~~~ 000002040000.png~~~ 000002390000.png~~~~~
000001700000.png~ 000002040000.png~~~~ 000002400000.png~
000001700000.png~~ 000002040000.png~~~~~ 000002400000.png~~
000001700000.png~~~ 000002050000.png~ 000002400000.png~~~
000001700000.png~~~~ 000002050000.png~~ 000002400000.png~~~~
000001700000.png~~~~~ 000002050000.png~~~ 000002400000.png~~~~~
000001710000.png~ 000002050000.png~~~~ 000002410000.png~
000001710000.png~~ 000002050000.png~~~~~ 000002410000.png~~
000001710000.png~~~ 000002060000.png~ 000002410000.png~~~
000001710000.png~~~~ 000002060000.png~~ 000002410000.png~~~~
000001710000.png~~~~~ 000002060000.png~~~ 000002410000.png~~~~~
000001720000.png~ 000002060000.png~~~~ 000002420000.png~
000001720000.png~~ 000002060000.png~~~~~ 000002420000.png~~
000001720000.png~~~ 000002070000.png~ 000002420000.png~~~
000001720000.png~~~~ 000002070000.png~~ 000002420000.png~~~~
000001720000.png~~~~~ 000002070000.png~~~ 000002420000.png~~~~~
000001730000.png~ 000002070000.png~~~~ 10.png
000001730000.png~~ 000002070000.png~~~~~ 11.png
000001730000.png~~~ 000002080000.png~ 12.png
000001730000.png~~~~ 000002080000.png~~ 13.png
000001730000.png~~~~~ 000002080000.png~~~ 14.png
000001740000.png~ 000002080000.png~~~~ 15.png
000001740000.png~~ 000002080000.png~~~~~ 16.png
000001740000.png~~~ 000002090000.png~ 17.png
000001740000.png~~~~ 000002090000.png~~ 18.png
000001740000.png~~~~~ 000002090000.png~~~ 19.png
000001750000.png~ 000002090000.png~~~~ 1.png
000001750000.png~~ 000002090000.png~~~~~ 20.png
000001750000.png~~~ 000002100000.png~ 21.png
000001750000.png~~~~ 000002100000.png~~ 22.png
000001750000.png~~~~~ 000002100000.png~~~ 23.png
000001760000.png~ 000002100000.png~~~~ 24.png
000001760000.png~~ 000002100000.png~~~~~ 25.png
000001760000.png~~~ 000002110000.png~ 26.png
000001760000.png~~~~ 000002110000.png~~ 27.png
000001760000.png~~~~~ 000002110000.png~~~ 28.png
000001770000.png~ 000002110000.png~~~~ 29.png
000001770000.png~~ 000002110000.png~~~~~ 2.png
000001770000.png~~~ 000002120000.png~ 30.png
000001770000.png~~~~ 000002120000.png~~ 31.png
000001770000.png~~~~~ 000002120000.png~~~ 32.png
000001780000.png~ 000002120000.png~~~~ 33.png
000001780000.png~~ 000002120000.png~~~~~ 34.png
000001780000.png~~~ 000002130000.png~ 35.png
000001780000.png~~~~ 000002130000.png~~ 36.png
000001780000.png~~~~~ 000002130000.png~~~ 37.png
000001790000.png~ 000002130000.png~~~~ 38.png
000001790000.png~~ 000002130000.png~~~~~ 39.png
000001790000.png~~~ 000002140000.png~ 3.png
000001790000.png~~~~ 000002140000.png~~ 40.png
000001790000.png~~~~~ 000002140000.png~~~ 41.png
000001800000.png~ 000002140000.png~~~~ 42.png
000001800000.png~~ 000002140000.png~~~~~ 43.png
000001800000.png~~~ 000002150000.png~ 44.png
000001800000.png~~~~ 000002150000.png~~ 45.png
000001800000.png~~~~~ 000002150000.png~~~ 46.png
000001810000.png~ 000002150000.png~~~~ 47.png
000001810000.png~~ 000002150000.png~~~~~ 48.png
000001810000.png~~~ 000002160000.png~ 49.png
000001810000.png~~~~ 000002160000.png~~ 4.png
000001810000.png~~~~~ 000002160000.png~~~ 50.png
000001820000.png~ 000002160000.png~~~~ 51.png
000001820000.png~~ 000002160000.png~~~~~ 52.png
000001820000.png~~~ 000002170000.png~ 53.png
000001820000.png~~~~ 000002170000.png~~ 54.png
000001820000.png~~~~~ 000002170000.png~~~ 55.png
000001830000.png~ 000002170000.png~~~~ 56.png
000001830000.png~~ 000002170000.png~~~~~ 57.png
000001830000.png~~~ 000002180000.png~ 58.png
000001830000.png~~~~ 000002180000.png~~ 59.png
000001830000.png~~~~~ 000002180000.png~~~ 5.png
000001840000.png~ 000002180000.png~~~~ 60.png
000001840000.png~~ 000002180000.png~~~~~ 61.png
000001840000.png~~~ 000002190000.png~ 62.png
000001840000.png~~~~ 000002190000.png~~ 63.png
000001840000.png~~~~~ 000002190000.png~~~ 64.png
000001850000.png~ 000002190000.png~~~~ 65.png
000001850000.png~~ 000002190000.png~~~~~ 66.png
000001850000.png~~~ 000002200000.png~ 67.png
000001850000.png~~~~ 000002200000.png~~ 68.png
000001850000.png~~~~~ 000002200000.png~~~ 69.png
000001860000.png~ 000002200000.png~~~~ 6.png
000001860000.png~~ 000002200000.png~~~~~ 70.png
000001860000.png~~~ 000002210000.png~ 71.png
000001860000.png~~~~ 000002220000.png~ 72.png
000001860000.png~~~~~ 000002220000.png~~ 73.png
000001870000.png~ 000002220000.png~~~ 74.png
000001870000.png~~ 000002220000.png~~~~ 75.png
000001870000.png~~~ 000002220000.png~~~~~ 76.png
000001870000.png~~~~ 000002230000.png~ 77.png
000001870000.png~~~~~ 000002230000.png~~ 78.png
000001880000.png~ 000002230000.png~~~ 79.png
000001880000.png~~ 000002230000.png~~~~ 7.png
000001880000.png~~~ 000002230000.png~~~~~ 80.png
000001880000.png~~~~ 000002240000.png~ 81.png
000001880000.png~~~~~ 000002240000.png~~ 82.png
000001890000.png~ 000002240000.png~~~ 83.png
000001890000.png~~ 000002240000.png~~~~ 84.png
000001890000.png~~~ 000002240000.png~~~~~ 85.png
000001890000.png~~~~ 000002250000.png~ 86.png
000001890000.png~~~~~ 000002250000.png~~ 8.png
000001900000.png~ 000002250000.png~~~ 9.png
000001900000.png~~ 000002250000.png~~~~
000001900000.png~~~ 000002250000.png~~~~~
The output of the second ls is:
100.png 148.png 196.png 244.png 292.png 340.png 388.png 436.png 484.png
101.png 149.png 197.png 245.png 293.png 341.png 389.png 437.png 485.png
102.png 150.png 198.png 246.png 294.png 342.png 390.png 438.png 486.png
103.png 151.png 199.png 247.png 295.png 343.png 391.png 439.png 487.png
104.png 152.png 200.png 248.png 296.png 344.png 392.png 440.png 488.png
105.png 153.png 201.png 249.png 297.png 345.png 393.png 441.png 489.png
106.png 154.png 202.png 250.png 298.png 346.png 394.png 442.png 490.png
107.png 155.png 203.png 251.png 299.png 347.png 395.png 443.png 491.png
108.png 156.png 204.png 252.png 300.png 348.png 396.png 444.png 492.png
109.png 157.png 205.png 253.png 301.png 349.png 397.png 445.png 493.png
110.png 158.png 206.png 254.png 302.png 350.png 398.png 446.png 494.png
111.png 159.png 207.png 255.png 303.png 351.png 399.png 447.png 495.png
112.png 160.png 208.png 256.png 304.png 352.png 400.png 448.png 496.png
113.png 161.png 209.png 257.png 305.png 353.png 401.png 449.png 497.png
114.png 162.png 210.png 258.png 306.png 354.png 402.png 450.png 498.png
115.png 163.png 211.png 259.png 307.png 355.png 403.png 451.png 499.png
116.png 164.png 212.png 260.png 308.png 356.png 404.png 452.png 500.png
117.png 165.png 213.png 261.png 309.png 357.png 405.png 453.png 501.png
118.png 166.png 214.png 262.png 310.png 358.png 406.png 454.png 502.png
119.png 167.png 215.png 263.png 311.png 359.png 407.png 455.png 503.png
120.png 168.png 216.png 264.png 312.png 360.png 408.png 456.png 504.png
121.png 169.png 217.png 265.png 313.png 361.png 409.png 457.png 505.png
122.png 170.png 218.png 266.png 314.png 362.png 410.png 458.png 506.png
123.png 171.png 219.png 267.png 315.png 363.png 411.png 459.png 507.png
124.png 172.png 220.png 268.png 316.png 364.png 412.png 460.png 508.png
125.png 173.png 221.png 269.png 317.png 365.png 413.png 461.png 509.png
126.png 174.png 222.png 270.png 318.png 366.png 414.png 462.png 510.png
127.png 175.png 223.png 271.png 319.png 367.png 415.png 463.png 511.png
128.png 176.png 224.png 272.png 320.png 368.png 416.png 464.png 512.png
129.png 177.png 225.png 273.png 321.png 369.png 417.png 465.png 513.png
130.png 178.png 226.png 274.png 322.png 370.png 418.png 466.png 514.png
131.png 179.png 227.png 275.png 323.png 371.png 419.png 467.png 515.png
132.png 180.png 228.png 276.png 324.png 372.png 420.png 468.png 516.png
133.png 181.png 229.png 277.png 325.png 373.png 421.png 469.png 517.png
134.png 182.png 230.png 278.png 326.png 374.png 422.png 470.png 87.png
135.png 183.png 231.png 279.png 327.png 375.png 423.png 471.png 88.png
136.png 184.png 232.png 280.png 328.png 376.png 424.png 472.png 89.png
137.png 185.png 233.png 281.png 329.png 377.png 425.png 473.png 90.png
138.png 186.png 234.png 282.png 330.png 378.png 426.png 474.png 91.png
139.png 187.png 235.png 283.png 331.png 379.png 427.png 475.png 92.png
140.png 188.png 236.png 284.png 332.png 380.png 428.png 476.png 93.png
141.png 189.png 237.png 285.png 333.png 381.png 429.png 477.png 94.png
142.png 190.png 238.png 286.png 334.png 382.png 430.png 478.png 95.png
143.png 191.png 239.png 287.png 335.png 383.png 431.png 479.png 96.png
144.png 192.png 240.png 288.png 336.png 384.png 432.png 480.png 97.png
145.png 193.png 241.png 289.png 337.png 385.png 433.png 481.png 98.png
146.png 194.png 242.png 290.png 338.png 386.png 434.png 482.png 99.png
147.png 195.png 243.png 291.png 339.png 387.png 435.png 483.png
I would like to merge specific files (XXXXXXX_Abstract_TOC.txt, XXXXXXX_Chapter1.txt, XXXXXXX_Chapter2.txt, XXXXXXX_Chapter3.txt, XXXXXXX_Chapter4.txt, XXXXXXX_Conclusion.txt) into one file based on specific numbers that come from a text file(/util_files/list_NRPs.txt).
Note: X is [0-9] digit
The list_NRPs.txt contains as follows:
0030001
0030002
0030004
...
In /All_Files folder, I have files as follows:
0030001_Abstract_TOC.txt
0030001_Chapter1.txt
0030001_Chapter2.txt
0030001_Chapter3.txt
0030001_Chapter4.txt
0030001_Conclusion.txt
0030002_Abstract_TOC.txt
0030002_Chapter1.txt
0030002_Chapter2.txt
0030002_Chapter3.txt
0030002_Chapter4.txt
0030002_Conclusion.txt
0030004_Abstract_TOC.txt
0030004_Chapter1.txt
0030004_Chapter2.txt
0030004_Chapter3.txt
0030004_Chapter4.txt
0030004_Conclusion.txt
...
For each XXXXXXX from list_NRPs.txt I would like to merge XXXXXXX_Abstract_TOC.txt, XXXXXXX_Chapter1.txt, XXXXXXX_Chapter2.txt, XXXXXXX_Chapter3.txt, XXXXXXX_Chapter4.txt, XXXXXXX_Conclusion.txt into XXXXXXX_All.txt.
The final process in /All_Files folder would be:
0030001_Abstract_TOC.txt
0030001_Chapter1.txt
0030001_Chapter2.txt
0030001_Chapter3.txt
0030001_Chapter4.txt
0030001_Conclusion.txt
0030001_All.txt
0030002_Abstract_TOC.txt
0030002_Chapter1.txt
0030002_Chapter2.txt
0030002_Chapter3.txt
0030002_Chapter4.txt
0030002_Conclusion.txt
0030002_All.txt
0030004_Abstract_TOC.txt
0030004_Chapter1.txt
0030004_Chapter2.txt
0030004_Chapter3.txt
0030004_Chapter4.txt
0030004_Conclusion.txt
0030004_All.txt
...
I would like start with cat ../util_files/list_NRPs.txt | xargs but I do not know how to proceed.
How can I do that?
You can use globbing to concatenate multiple files matching each line in list_NRPs.txt file:
while read -r ch; do
cat "/All_Files/$ch"* > "/All_Files/${ch}_All.txt"
done < /util_files/list_NRPs.txt
I have a Makefile which looks roughly like this:
FIGURES = A1_B1_C1.eps A2_B2_C2.eps A3_B3_C3.eps
NUMBERS = 1 2 3
all : $(FIGURES)
%.eps : $(foreach num, $(NUMBERS), $(subst B, $(num), %).out)
# my_program($+, $#);
%.out :
The point is that the file names of my figures contain certain information (A, B, C) and that each figure is created by my_program from several (in the example 3) files.
While the filename of each figure has the format Ax_Bx_Cx.eps, the names of the data files to create the figures from look like this:
Ax_1x_Cx.out
Ax_2x_Cx.out
Ax_3x_Cx.out
So for each figure, I need a dynamically created dependency list with several file names. In other words, my desired output for the example above would be:
# my_program(A1_11_C1.out A1_21_C1.out A1_31_C1.out, A1_B1_C1.eps);
# my_program(A2_12_C2.out A2_22_C2.out A2_32_C2.out, A2_B2_C2.eps);
# my_program(A3_13_C3.out A3_23_C3.out A3_33_C3.out, A3_B2_C3.eps);
Unfortunately, the subst command seems to be ignored, for the output looks like this:
# my_program(A1_B1_C1.out A1_B1_C1.out A1_B1_C1.out, A1_B1_C1.eps);
# my_program(A2_B2_C2.out A2_B2_C2.out A2_B2_C2.out, A2_B2_C2.eps);
# my_program(A3_B3_C3.out A3_B3_C3.out A3_B3_C3.out, A3_B3_C3.eps);
I had a look at this possible duplicate but figured that the answer cannot help me, since I am using % and not $#, which should be ok in the prerequisites.
Clearly I am getting something wrong here. Any help is greatly appreciated.
To do fancy prerequisite manipulations you need at least make-3.82 which supports Secondary Expansion feature:
FIGURES = A1_B1_C1.eps A2_B2_C2.eps A3_B3_C3.eps
NUMBERS = 1 2 3
all : $(FIGURES)
.SECONDEXPANSION:
$(FIGURES) : %.eps : $$(foreach num,$$(NUMBERS),$$(subst B,$$(num),$$*).out)
#echo "my_program($+, $#)"
%.out :
touch $#
Output:
$ make
touch A1_11_C1.out
touch A1_21_C1.out
touch A1_31_C1.out
my_program(A1_11_C1.out A1_21_C1.out A1_31_C1.out, A1_B1_C1.eps)
touch A2_12_C2.out
touch A2_22_C2.out
touch A2_32_C2.out
my_program(A2_12_C2.out A2_22_C2.out A2_32_C2.out, A2_B2_C2.eps)
touch A3_13_C3.out
touch A3_23_C3.out
touch A3_33_C3.out
my_program(A3_13_C3.out A3_23_C3.out A3_33_C3.out, A3_B3_C3.eps)
I am trying to set variables for gnuplot environment with set for cycle command.
I am using 4.6 version and according the gnuplot documention (page 70) the syntax is following:
for [intvar = start:end{:increment}]
for [stringvar in "A B C D"]
Examples:
set for [i = 1:10] style line i lc rgb "blue"
But i get this error:
gnuplot> set for [var in gpvars] replace(var,'#_#',' ')
^
line 0: Unrecognized option. See 'help set'.
My script:
#!/bin/bash
OUTDIRNAME="out"
TIMEFORMAT='%d.%m.%y'
GPPARS=( "xlabel "Time"" "ylabel "value1"" "y2label "value2"" "format x "%H:%M"")
GPPARS_MOD=()
for (( i=0; i < ${#GPPARS[#]}; i++)); do
FILE=${GPPARS[${i}]}
echo "arg=${FILE}"
GPPARS_MOD+=( "`echo "${FILE}" | sed -e 's/ /#_#/g'`" )
done
gnuplot << EOF
reset
replace(S,C,R)=(strstrt(S,C)) ? \
replace( S[:strstrt(S,C)-1].R.S[strstrt(S,C)+strlen(C):] ,C,R) : S
set terminal png
set output "${OUTDIRNAME}/graph.png"
set timefmt "${TIMEFORMAT}"
set xdata time
gpvars="${GPPARS_MOD[#]}"
set for [var in gpvars] {
replace(var,'#_#',' ')
}
...
EOF
...
exit 0
I am also using function replace, because spaces ( gnuplot ignores escape sequences )The function works flawlessly for plot for cycle.
I have tried with and without function and with variables without spaces, but the result is same.
As a side note -- I'm not sure that I believe your bash array will group things the way you want it to ... for me, your quotations get stripped. try:
GPPARS=( "xlabel 'Time'" "ylabel 'value1'" "y2label 'value2'" "format x '%H:%M'")
instead. (interior double quotes replaced with single quotes)
This is a tricky one -- It's a good thing you're using gnuplot 4.6, otherwise I'm not sure how to go about solving it. (EDIT -- using gnuplot 4.4, you could use a combination of word, words, if, reread, exists and macros, but it's quite a messy solution)
Note that what you have doesn't work because it is akin to:
MYLABEL='xlabel "foo"'
set MYLABEL
Gnuplot doesn't expand MYLABEL prior to doing the set command so that you can do things like:
MYLABEL="totally cool X label here!"
set xlabel MYLABEL
What you want could be accomplished using macros (but alas, not with iteration):
set macro
MYLABEL='xlabel "foo"'
set #MYLABEL
But that doesn't quite work here either because macro expansion happens before anything else (e.g. function evaluation). What you need here is gnuplot's more general iteration introduced in 4.6 combined with eval
do for [ var in gpvars ] {
eval( 'set '.replace(var,'#_#',' ') )
}
EDIT -- gnuplot 4.2+ solution
#top of script -- Nothing should go here.
replace(S,C,R)=(strstrt(S,C)) ? \
replace( S[:strstrt(S,C)-1].R.S[strstrt(S,C)+strlen(C):] ,C,R) : S
if( ! exists("N") ) N=1
TODO="${GPPARS_MOD[#]}"
set macro
do_set=replace(word(TODO,N),'#_#',' ')
set #do_set
N=N+1
if( N <= words(TODO) ) reread
#rest of script here ...
I have many references in Referencer. I'm trying to include filenames in my bibtex file when exporting from Referencer. Since the software doesn't do this by default I'm trying to use a sed command to include the filename as a bibtex information in the XML file before I export and thus include the filename.
Input
<doc>
<filename>file:///home/dwickrama/Desktop/stevenJonesLab/papers/Transcription%20Factor%20Binding/A%20Common%20Nuclear%20Signal%20Transduction%20Pathway%20Activated%20by%20Growth%20Factor%20and%20Cytokine.pdf</filename>
<relative_filename>A%20Common%20Nuclear%20Signal%20Transduction%20Pathway%20Activated%20by%20Growth%20Factor%20and%20Cytokine.pdf</relative_filename>
<key>Sadowski93</key>
<notes></notes>
<bib_type>article</bib_type>
<bib_doi></bib_doi>
<bib_title>A common nuclear signal transduction pathway activated by growth factor and cytokine receptors.</bib_title>
<bib_authors>Sadowski, H B and Shuai, K and Darnell, J E and Gilman, M Z</bib_authors>
<bib_journal>Science</bib_journal>
<bib_volume>261</bib_volume>
<bib_number>5129</bib_number>
<bib_pages>1739-44</bib_pages>
<bib_year>1993</bib_year>
<bib_extra key="pmid">8397445</bib_extra>
Ouput
<doc>
<filename>file:///home/dwickrama/Desktop/stevenJonesLab/papers/Transcription%20Factor%20Binding/A%20Common%20Nuclear%20Signal%20Transduction%20Pathway%20Activated%20by%20Growth%20Factor%20and%20Cytokine.pdf</filename>
<bib_extra key="File">article:../Transcription\ Factor\ Binding/A\ Common\ Nuclear\ Signal\ Transduction\ Pathway\ Activated\ by\ Growth\ Factor\ and\ Cytokine.pdf:pdf</bib_extra>
<relative_filename>A%20Common%20Nuclear%20Signal%20Transduction%20Pathway%20Activated%20by%20Growth%20Factor%20and%20Cytokine.pdf</relative_filename>
<key>Sadowski93</key>
<notes></notes>
<bib_type>article</bib_type>
<bib_doi></bib_doi>
<bib_title>A common nuclear signal transduction pathway activated by growth factor and cytokine receptors.</bib_title>
<bib_authors>Sadowski, H B and Shuai, K and Darnell, J E and Gilman, M Z</bib_authors>
<bib_journal>Science</bib_journal>
<bib_volume>261</bib_volume>
<bib_number>5129</bib_number>
<bib_pages>1739-44</bib_pages>
<bib_year>1993</bib_year>
<bib_extra key="pmid">8397445</bib_extra>
I can use the following sed command to partially do what I want, but the URL encoding "%20" remains. How do I get rid of that in only the bibtex tag ?
sed -e 's/\(\ \ \ \ <filename>file:\/\/\/home\/dwickrama\/Desktop\/stevenJonesLab\/papers\)\([^.]*\)\(\.\?\)\(.*\)\(<\/filename>\)/\1\2\3\4\5\n\ \ \ \ <bib_extra\ key=\"File\">article:\.\.\2\3\4:\4<\/bib_extra>/g' NewPapers.reflib > NewPapers.new.reflib
Regex and sed are not very good tools for processing XML, or URL-decoding.
A quick script in more complete scripting language would be able to do it more clearly and reliably. For example in Python:
import urllib, urlparse
from xml.dom import minidom
doc= minidom.parse('NewPapers.reflib')
el= doc.getElementsByTagName('filename')[0]
path= urlparse.urlparse(el.firstChild.data)[2]
foldername, filename= map(urllib.unquote, path.split('/')[-2:])
extra= doc.createElement('bib_extra')
extra.setAttribute('key', 'File')
extra.appendChild(document.createTextNode('article:../%s/%s:pdf' % (foldername, filename)))
el.parentNode.insertBefore(extra, el.nextSibling)
doc.writexml(open('NewPapers.new.reflib'))
(I haven't included a function to reproduce the backslash-escaping in the given example output as it's not clearly exactly what format that is. The simplest approach would be filename= filename.replace(' ', '\\ '), but I'm not sure that would be correct.)
all you need is to add a line after right?? So just print it out after is searched.
#!/bin/bash
s='<bib_extra key="File">article:../Transcription\\ Factor\\ Binding/A\\ Common\\ Nuclear\\ Signal\\ Transduction\\ Pathway\\ Activated\\ by\\ Growth\\ Factor\\ and\\ Cytokine.pdf:pdf</bib_extra>'
awk -vstr="$s" '
/<filename>/{
print
print str;next
}
{print}' file