unix

Trying to remove non-printable charaters(junk values) from a UNIX file

一曲冷凌霜 提交于 2021-01-20 04:15:04
问题 I am trying to remove non-printable character (for e.g. ^@ ) from records in my file. Since the volume to records is too big in the file using cat is not an option as the loop is taking too much time. I tried using sed -i 's/[^@a-zA-Z 0-9`~!@#$%^&*()_+\[\]\\{}|;'\'':",.\/<>?]//g' FILENAME but still the ^@ characters are not removed. Also I tried using awk '{ sub("[^a-zA-Z0-9\"!@#$%^&*|_\[](){}", ""); print } FILENAME > NEW FILE but it also did not help. Can anybody suggest some alternative

Moving the cursor to the beginning of the current line

和自甴很熟 提交于 2021-01-18 05:36:26
问题 I want to print current time (by using printf) in same place, but i want to do it in infinite loop eg: while(1) {printf("Date and Time are %s", asctime(localtime(&current))); } . So before i use printf i should move cursor backward to its staring position. How to do it ? thx in advance 回答1: For simply moving the cursor to the beginning of the current line, you may print "\r", which does just that. Notice that it does not erase the old text, so be careful to either overwrite it or to clear

Get the characters after the last index of a substring from a string

假如想象 提交于 2021-01-16 12:38:50
问题 I have a string which is an output of another command. I only need the end of this string to display. The separator string is " . " (dot and space), and I need the string after the last index of " . ". How can I do this in Bash? 回答1: try this: your cmd...|sed 's/.*\. //' this works no matter how many "dot" or "dot and space" do you have in your input. it takes the string after the last "dot and space" 回答2: If the string is in a variable: $ foo="header. stuff. more stuff" $ echo "${foo##*. }"

Get the characters after the last index of a substring from a string

。_饼干妹妹 提交于 2021-01-16 12:36:17
问题 I have a string which is an output of another command. I only need the end of this string to display. The separator string is " . " (dot and space), and I need the string after the last index of " . ". How can I do this in Bash? 回答1: try this: your cmd...|sed 's/.*\. //' this works no matter how many "dot" or "dot and space" do you have in your input. it takes the string after the last "dot and space" 回答2: If the string is in a variable: $ foo="header. stuff. more stuff" $ echo "${foo##*. }"

“command not found” when running shell script

我怕爱的太早我们不能终老 提交于 2021-01-05 07:20:27
问题 Here is the simple script.sh file I have: #!/bin/bash pwd date ls -lg I have used chmod +x to make the file executable, but when running it with ./script.sh I get command not found: pwd command not found: date and only the ls -lg command works. I'm a bit perplexed as to why the first two commands aren't working because when I type them into the command terminal they work the way they should. 回答1: Maybe there is a (invisible) character there that should not be there. Try typing it again from

Copying local files with curl [closed]

大城市里の小女人 提交于 2021-01-02 05:17:28
问题 Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . Improve this question Is there a way to copy local files with curl, I need it to work as an alternative for cp command. This is a bit strange, but I'm working on an environment where cp is not available. 回答1: You could say: curl -o /path/to/destination file:///path/to/source/file This

My JSch session doesn't execute command

末鹿安然 提交于 2021-01-01 06:37:37
问题 I'm trying to write a Java code that can ssh into a Unix server and reset a user's password. So I tried to implement some of the code found in SO. Eg. Sending commands to remote server through ssh by Java with JSch Take commands(password) from string and set as InputStream to Unix servers in Java (JSCH) Using JSch ChannelExec , I followed this link to get the proper command for resetting user's password. When I tried running this code, seems like it doesn't reset the user's password. So I

moving a file with spaces in name

痴心易碎 提交于 2021-01-01 05:12:43
问题 I have a file in unix with name as "this is my file.xls" I want to move it from one folder to other. I wrote the below lines: fileName="this is my file" myDate=20121125 mv $FIRST_DIR/"${fileName}.xls" $SECOND_DIR/"${fileName}_${myDate}.xls" However, this is not working. I am getting error as "file.xls is not a directory" What is the correct way to do this? Thanks for reading! 回答1: Use escape characters for spaces. So change the variable fileName to "this\ is\ my\ file". This ensures that the

moving a file with spaces in name

廉价感情. 提交于 2021-01-01 05:12:03
问题 I have a file in unix with name as "this is my file.xls" I want to move it from one folder to other. I wrote the below lines: fileName="this is my file" myDate=20121125 mv $FIRST_DIR/"${fileName}.xls" $SECOND_DIR/"${fileName}_${myDate}.xls" However, this is not working. I am getting error as "file.xls is not a directory" What is the correct way to do this? Thanks for reading! 回答1: Use escape characters for spaces. So change the variable fileName to "this\ is\ my\ file". This ensures that the

ffmpeg exit status -1094995529

故事扮演 提交于 2020-12-30 07:38:27
问题 I'm developing an application that makes calls to ffprobe that return the unorthodox exit status of -1094995529 for certain files when on Windows. This exit status is given consistently, and there is some minor discussion of this. Why is this value given, and where is it documented? Can I expect this status to be different on a unix machine where the allowed exit statuses are more constrained? 回答1: Error codes from ffmpeg (error.h from avutil) : http://ffmpeg.org/doxygen/trunk/error_8h_source