Skip to content
Advertisement

Tag: bash

How to delete duplicated rows based in a column value?

Given the following table Using a bash shell script based in Linux, I’d like to delete all the rows based on the value of column 1 (The one with the long number). Having into consideration that this number is a variable number I’ve tried with awk ‘{a[$3]++}!(a[$3]-1)’ file But I am not getting the result which would be something like

While loop not equal command not found

I am trying to perform a simple while loop comparing a variable to a string. It fails to load with the error on this line. Error states [: missing `]’ and : command not found. My while loop looks like; Answer There are a couple of errors: See that variable declaration do need to be like var=value. Otherwise, bash would

Check if a directory exists and is accessible

I want to check if a directory exists and it has access rights; if it does, then perform the tasks. This is the code I wrote, which might not have proper syntax. Can you help me to correct it? I believe this can also be written like this. How can we write this more efficiently? Answer The best way to

sending email in linux as subject and attachment

I have a file that is about 10 columns wide and try to send it as body. mailx fails sending it as body and sends it as a ATT00001.bin file and as an attachment. mail -s “Subject” emailaddress < file.tsv Is there way to solve this. When I try to send it as an attachment, using uuencode echo “body” |

cut or awk command to print first field of first row

I am trying print the first field of the first row of an output. Here is the case. I just need to print only SUSE from this output. Tried with cat /etc/*release | awk {‘print $1}’ but that print the first string of every row Answer Specify NR if you want to capture output from selected rows: An alternative (ugly)

Shell script: Run function from script over ssh

Is there any clever way to run a local Bash function on a remote host over ssh? For example: Yeah, I know it doesn’t work, but is there a way to achieve this? Answer You can use the typeset command to make your functions available on a remote machine via ssh. There are several options depending on how you want

linux sed, do insert and append at the same time

I have a question about linux sed command. I just want to insert something before every line and append something after every line. And i want to do these things at the same time. For example, assume file.txt is like: I need to output: so I think the command should be like: But the result is not right, a is

not allow multiple option in getopts of bash script

Having bash script as follows Above script run fine with different option but i wanted to extend it to not allow to pass multiple option at same time like as following argument should be not valid means some way it give me error like wrong syntax i achieved it by as follows but it seems to long it is as

How do I change the group ownership of a file in Ubuntu? [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

Advertisement