Processing background of seq in a shell: extract the content of the file using shell. the file name is generated using the serial number below. There are nearly 400 million file records as follows: www.2cto.com original script #! /Bin/sh # str1 & quot; # filecount 'ls-l/root/gjj | wc-l... one-time shell seq processing
Background: use shell to extract the content in the file. the file name is generated using the serial number below. There are nearly 400 million files as follows:
Original www.2cto.com script
#! /Bin/sh
# Str1 = ""
In the script, $1 and $2 represent the starting serial number.
At the beginning, it was normal to use this script to extract the file content. However, when the file name contains seven digits, the following error occurs:
As follows:
[Root @ ALL ~] # Sh tiqu. sh 2908637 2908640
/Windows_gjj/2.90864e000006.txt
Dos2unix: converting file/windows_gjj/2.90864e000006.txt to UNIX format...
Dos2unix: problems converting file/windows_gjj/2.90864e000006.txt
Sed: unable to read/windows_gjj/2.90864e000006.txt: no file or directory
Sed: unable to read/windows_gjj/2.90864e000006.txt: no file or directory
Sed: unable to read/windows_gjj/2.90864e000006.txt: no file or directory
Sed: unable to read/windows_gjj/2.90864e000006.txt: no file or directory
Sed: unable to read/windows_gjj/2.90864e000006.txt: no file or directory
Sed: unable to read/windows_gjj/2.90864e000006.txt: no file or directory
Grep:/windows_gjj/2.90864e000006.txt: the file or directory does not exist.
Cat:/windows_gjj/2.90864e000006.txt: the file or directory does not exist.
Wc:/windows_gjj/2.90864e000006.txt: the file or directory does not exist.
Sed: unable to read/windows_gjj/2.90864e000006.txt: no file or directory
Head: unable to open "/windows_gjj/2.90864e000006.txt" to read data: No such file or directory
|
Sed: unable to read/windows_gjj/2.90864e000006.txt: no file or directory
Sed: unable to read/windows_gjj/2.90864e000006.txt: no file or directory
Head: unable to open "/windows_gjj/2.90864e000006.txt" to read data: No such file or directory
|
Sed: unable to read/windows_gjj/2.90864e000006.txt: no file or directory
Sed: unable to read/windows_gjj/2.90864e000006.txt: no file or directory
Head: unable to open "/windows_gjj/2.90864e000006.txt" to read data: No such file or directory
Analysis: The main cause of this problem is that the shell expresses the 7-digit number in the form of an exponential, resulting in the failure to find the corresponding file.
Solution: in order to enable the 7-digit display as a number, the-f,-w and other options in seq fail to achieve the expected effect. Finally, the compromise method is adopted, the highest bit is replaced by characters, and the last 6 is generated by seq. the parameter-w is used to keep the width of the digits consistent. the script for repairing this is as follows:
#! /Bin/sh
# Str1 = ""
[Root @ ALL ~] # Sh tiqu. sh 908636 908640
/Windows_gjj/2908636.txt
Dos2unix: converting file/windows_gjj/2908636.txt to UNIX format...
|
/Windows_gjj/2908637.txt
Dos2unix: converting file/windows_gjj/2908637.txt to UNIX format...
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.