I have several files whose extensions are .gz with similar filenames to:
ANKR00TUR_R_20183350000_01D_30S_MO.crx.gz
I need to read the first four characters of these files' names and store these characters in a file. How can I do this?
I have several files whose extensions are .gz with similar filenames to:
ANKR00TUR_R_20183350000_01D_30S_MO.crx.gz
I need to read the first four characters of these files' names and store these characters in a file. How can I do this?
Here the code to take first four character of filenames;
Result:
Source
For a list
previous for cycle will print on the screen the result and also append to list.txt
Source from Documentation on The Linux Documentation Project (TLDP)
Update Improvement of code based on @steeldriver suggestion in comment.
To fetch the first N bytes of a string,
cut
can be used:This will extract the first 4 bytes from the given string and store it in the file
output
.To apply the above code to multiple filenames, use