Mel
  • Member for 6 years, 6 months
  • Last seen more than a month ago
ssh command with quotes
Accepted answer
7 votes

for i in `cat servlist`;do echo $i;ssh $i 'sudo usermod -c "New Comment" user';done or for i in `cat servlist`;do echo $i;ssh $i "sudo usermod -c \"New Comment\" user";done

View answer
iptables to block all websites
Accepted answer
4 votes

iptables -I OUTPUT -p tcp -m tcp --dport 443 -j REJECT --reject-with icmp-port-unreachable iptables -I OUTPUT -p tcp -m tcp --dport 80 -j REJECT --reject-with icmp-port-unreachable iptables -I OUTPUT -...

View answer
How to output some data to different cells of an Excel File?
Accepted answer
3 votes

For "simple" columns like this, comma separated values will open nicely in excel. awk 'BEGIN{ OFS=","; print "Hosts,Output,Status"}; NR > 1{print $1, $2, $3, $4, $5, $6, $7, $8, $9;}' input.txt &...

View answer
Get environment variables of running session
3 votes

It sounds like you are trying to find the variable that a user has in their environment dynamically from an already running script as each process gets created? A method I have used to solve this is ...

View answer
How do I check if a variable exists in an 'if' statement?
3 votes

if set|grep '^somevar=' >/dev/null;then echo "somevar exists" else echo "does not exist" fi

View answer
Bash variable changes when inside quotes
Accepted answer
2 votes

Take out the quotes in the files line, which leaves: #!/bin/bash files=(*.sql) firstfile=${files[0]} echo $firstfile echo "The first file is $firstfile"

View answer
How to understand SNMP MIB?
Accepted answer
2 votes

It can be very tedious to chain it back manually. There are tools such as snmptranslate to do this sort of thing for you. Try snmptranslate -M /path/to/mibs -m ALL -Pu -Tso|grep -B1 sysUpTimeInstance. ...

View answer
Print alternating lines with conditional
Accepted answer
2 votes

If I understand you correctly, you only want lines containing X if they are then followed by a line containing Y, and then you want both lines. grep -A1 X filename |grep --no-group-separator -B1 Y

View answer
Searching for a string in all .txt files
1 votes

Assuming that by "all textfiles" you mean al files ending in .txt: find / -type f -name '*.txt' -exec grep -i 'test123' {} \; or find / -type f -name '*.txt' -exec grep -i 'test123' {} +

View answer
Move files/table following selection criteria
Accepted answer
1 votes

This is not supposed to be a "write this program for me" site, so I am assuming that you have no idea where to start. So here's one way: #!/bin/bash highest=-999 for x in a[0-9]/a[0-9].txt;do ...

View answer
How to execute R script attaching it to a shell script in Linux?
1 votes

I'm not familiar with R, but your script is attempting to run as a bash script, not an R script. Change your first line to #!/usr/bin/Rscript or possibly #!/usr/bin/env Rscript. You may need to alter ...

View answer
Merge duplicated lines which have the same first three fields
1 votes

sed -r ':a;N;s!;N/A!!g;s/^(([^;]*;){3})(.*)\n\1/\1\3;/;T;s!^(([^S][^;]*;){3,})(S*SM-[^;]*);(([^S][^;]*;){1,})(.*)!\1\4\3/\6!;ta' inputfile Even though the implied math of your comment for only 6 ...

View answer
How do you search ! in man sed?
1 votes

man -k \! Not sure that is what you are really asking?

View answer
Extract sequences from a fasta file
0 votes

A "simple Linux command" might look something like: sed 's/\(>[^ACGT]*_[0-9]\+\)\([ACGT]\+\)/\1\n\2\n/g' yourdnafile |egrep -B1 '^[ACGT]{1000}' The sed part breaks down the into 2 lines per set, ...

View answer
Trying to convert a simple C program into an AWK program
0 votes

The following should duplicate the function of your sample c code: #!/bin/awk -f BEGIN{ printf("Enter the name of a text file: ") getline file < "-" printf("Enter the pattern to search ...

View answer
parsing out duplicate barcodes in a separate line
0 votes

#!/bin/bash [ $# -ge 1 ] && [ -f "$1" ] || exit while read oneline;do for onecode in $oneline;do let count=1 outfile="output.$count" [ -f $outfile ] || touch $...

View answer
Current X driver
0 votes

lspci -k will show devices and modules loaded for them. You can grep it for the specific device you are looking for, such as 'VGA' lspci -k|grep -A2 VGA

View answer
How remove duplicates in same file and with if condition?
0 votes

awk ' { if($1$2==cust){ if(startdate<$3){ custline=$0 startdate=$3 enddate=$4 next } if(startdate==$3 && enddate<$4){ custline=$0 ...

View answer
Copy Month wise folders
0 votes

cp -r Main_Dir/Subdir1/2[3-9]* Main_Dir/Subdir1/3* Main_Dir/Subdir2/* Main_Dir/Subdir3/* newdir/

View answer
Creating a script that runs a simple command for all files in a directory
-2 votes

for x in *.html;do lynx $x --force-html --dump >${x%%.html}.txt done

View answer