I’m a little confused as to what this counts: Does it count the occurences of abcd in the 4 lines xyz? “wc -l” returns a different count than the number of lines present inside the file. Answer Prints every ‘xyz’ and 4 lines before from the file. zgrep -B 4 “xyz” <filename> Prints only lines, containing (case-insensitive) ‘abcd’. grep -i
Tag: unix
grep with star symbol
What is the difference between grep commands: and what is different if I search text as “text”. Answer grep requires (at least) two arguments — what you are searching for, and where you are searching for it. If the second argument is not provided, then it will use stdin instead. grep text* is waiting for stdin to provide it something
Error handling of user information in Unix
I need to do some error handling in the beginning of a script. If a user is not a member of a specific group then the script needs to exit. Answer or shorter:
How to use cut and paste commands as a single line command?
In Unix, I am trying to write a sequence of cut and paste commands (saving result of each command in a file) that inverts every name in the file(below) shortlist and places a coma after the last name(for example, bill johnson becomes johnson, bill). here is my file shortlist: I am able to cut from shortlist but not sure how
How can I make a ksh script terminate itself if any issues?
I have written a few ksh scripts, about 6 scripts. These are written to handle huge data files, something like 207 MB big. while running the script, sometimes it gets stuck and does not end. Human interruption is required. In production environment, I want it to run automatically, and should be able to end automatically if any issues without the
Better way of using the redirection symbol in conjunction with find -exec
My goal is to empty every file in a directory. I DON’T want to actually delete the file, I just want to delete it’s contents. If you want to do this with a single file you can do > file.txt If I want to run this operation on every file in a directory I can do this: Notice how the
How to traverse when using `cat` command? [closed]
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) Answer I think you are asking for a pager. For that
Is it possible to somehow undo the results of the mv command?
Here’s the problem. I had a bunch of files in a directory. Then I created another directory in that directory. Then I cobbled together this command: This command was supposed to take all the files in the directory and move them to that newly-created directory, but instead of providing the name of the directory, I screwed up and typed 1,
linux – created duplicate root user, cant login anymore.. what do i do? [closed]
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question
Why count differs between ls and ls -l linux command?
I had a directory with number of files and need to check the count of files present in it. I tried the following two commands: and found there are differences while using both commands. (ie. number of files is greater in the usage of second command while comparing to the first command.) I would like to know the changes happening