Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Am trying to redirect the file based on the length.
I have a file having the value, I like Linux
I have to create a new file base on length, 0-6 will provide me I like.
In case of line number we can redirect using,
head-100 file_name.txt > file_name_new.txt
Not sure how to redirect using length of the data.
Any suggestion will be helpful
When you say "length of data", do you mean number of characters of each line? If so you can use cut command:
head -n100 file_name.txt | cut -c 1-10 > file_name_new.txt
Where [1-10] is the range of the characters you want to keep.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I get an exit behind a series of commands that returns me a huge list of servers.
Which start like this:
...linux.sapsmftexp01 ...linux.sappiftexp01 ...linux.sapbwftexp01
..linux.radiuswifiexp01 ..linux.gitlabexp01 ..linux.redisccexp01
I need to get only the name information, i.e .:
sapsmftexp01
sappiftexp01
sapbwftexp01
When I have tried to do it with cut -d
It deprives me of others, the same happens with awk, but someone has told me that I can do it from right to left, but I don't know how to do it.
Could someone help me please?
With sed:
sed -r 's/(linux)|(\.)//g;s/ /\n/gp' file
First remove any occurrences of "linux" or full stop and then replace spaces for new lines.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
Provided that this sting is dynamic. If it is as Domain_1234_20180821230101.dat then I want 1234_20180821. How can I do that?
I.e., when Domain_12_20180821230101.dat then I want output as 12_20180821
A primitive solution that works for the examples you gave would be:
grep -oP '[0-9]+_[0-9]{8}' <<< "$string"
This will extract any substring consisting of a variable-length number, followed by an underscore, followed by an 8-digit number if present, else return nothing.
You can find more infos to help you understand this command and adjust it to your requirements if necessary under grep --help and https://www.regular-expressions.info/tutorial.html.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I want to sort a file in linux. sort -n file.txt doesn't work!
The file that i want to sort is this. Between each number there are 3 space. I want to sort according to the last number of each row.
20.799999 13.760000 -15.200000 -10.560000 20.000000 -5.00000
3.90001 -9.7705E-02 -0.95687 -0.167488 0.12431613 -0.7140
How do I sort the file?
Use the -g option to make numbers with exponentials work. To sort on the 6th field, use -k6. Put together, sort -g -k6 file.txt.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
How to travel in the shell using cat command? (arrow keys are not working)
cat > myfile
I think you are asking for a pager. For that you can use more or less (yes, these are the real names). As an example, you can use cat FILE | less or just less FILE. In there, you can scroll/search/... (exit with q).
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I want to search for a number in string that does not occur between numbers.
For example:
string="10003096,10007051,10003098,10007053,10000952,10002696,10003619,900004608"
If i search for 10003096, then it exists.
But if i search for 1000, then it means it does not exist.
Even if i search for 10000952,10002696, then it means it does not exist.
How can i write the shell script for this?
Please help.
I have tried various options with grep and sed but it does not help.
Pad both your 'needle' and 'haystack' with commas. E.g.
echo ",$string," | grep ",10007053,"