Skip to content

Tag: shell

edit the only lines which matches some word

I have to search a file for lines with some specific words and edit these lines as follows. The other lines should remain the same. For example: to be modified to: Can any one please help how to use AWK to achieve this. Regards Answer awk solution: Explanation: When brz or jp matches, save last field in last,…

get all aliases in linux shell

How to list all aliases defined in a shell. Like the command below to list all files/folders in a directory I have defined some alias in ~/.bashrc i want to list all that command Answer Are you wondering if you have a UNIX alias already set for a specific command? You can find it easily by issuing this on the

Shell script to edit and add a entry in file

Could any one help me to add entry at the end of the line. This is linux os. Below is the contents of the file /boot/grub2/grub.cfg I need to add entry at the end of the line “text1” and “text2”. after edit my file should look like: Answer With sed expression:

Listing files with numeric names

How do I list files that have only numeric names e.g I have tried ls -l [0-9]* but this seems to bring all file names that start with a digit and can have anything in their name after a digit. Answer First, turn on Bash’s extglob option: Then use this pattern: Read more about extended pattern matching i…

Shell param doesn’t pass with command

I use the following code to execute shell command, the issue is that when I put it as parameter which I should get from user it doesn’t work but If I put it hard-coded it works. Working Not working In the not working version which I do cat to param I see the value printed OK, what could I miss

Using a compiled Python shell in Linux

Is it possible to use a “more complex” shell than just a single command shell? We have written a python shell that is a command loop, and it works fine in /etc/passwd like this: Of course the Python file has the shebang line for /usr/bin/python in it. However, we’d like to compile the Python…