Rakesh.N
  • Member for 5 years, 4 months
  • Last seen more than a week ago
Delete lines containing empty fields
Accepted answer
9 votes

Try with this one : awk '$7!=""' file > final_output

View answer
How to get exit status of a particular command in a pipeline?
Accepted answer
6 votes

you can make use of PIPESTATUS variable to get the exit status of each element of the pipeline. if [ ${PIPESTATUS[0]} -ne 0 ];then echo "mysqldump Query executed with error !!" exit 1 ...

View answer
Get disk usage as a shell variable
Accepted answer
4 votes

Try with this : df -hP /disk/path | awk '{print $5}' |tail -1|sed 's/%$//g'

View answer
Invalid multicast interface
Accepted answer
4 votes

Not much experience in freebsd system, as far as i know for ping try: ping -S 192.168.1.2 192.168.1.1 As for arp If arp cant fetch mac address of your gateway then freebsd server lost it's ...

View answer
Keep lines containing only 3 fields
Accepted answer
3 votes

This will help: awk -F':' 'NF==3{print}{}' file

View answer
Remove string between two different delimiters
Accepted answer
3 votes

Hope this will work: sed -i 's/:[0-9]*\.[0-9]*,/,/g' YourFile

View answer
How to view the size of the binary files using linux command?
Accepted answer
3 votes

Maybe this will work stat -c %s /data/local/tools/bin/csimu

View answer
Why won't the root processes sort when I attempt sorting the users based on the number of processes running?
Accepted answer
2 votes

This will work: ps -eo user|sort|uniq -c|sort -gr sort -gr is the key to it. -g : Sort numerically.

View answer
Extract all image names with sub folder names into CSV file using shell script
Accepted answer
1 votes

Try with this: find ~/Desktop -iname "*.jpg" -exec ls {} + | awk -F'/' ' BEGIN { OFS=", "; print "Image Name", "Category", "Subcategory", "type"} { print $(NF-1),$4, $5, $3 "" }' If you want to ...

View answer
How to add a newline in xargs
Accepted answer
1 votes

If you're okay with awk, try this solution: find $PWD -name copyright | xargs awk 'BEGIN{ORS=","} FNR==1{print "\n"FILENAME}; $0 ~ /^License/ {print $0}' | sed 's/,$//g' |awk -F',' 'NF>1'

View answer
Adding timestamp to TOP command output
1 votes

top -n 1 -b | grep -Ev "Tasks:|Swap:|Cpu|Mem:" > top_file grep "PID" top_file > top_test sed -i '/PID/d;/top/d;/^$/d' top_file awk '{print strftime("%m-%d-%Y-%H:%M:%S", systime())" " $0}' ...

View answer
How to move all files with a certain file extension from subdirectories to a single directory
1 votes

Try with this code: find /home/andhra1 -maxdepth 3 -name "*.txt" -type f -exec mv '{}' destinationPath/ \;

View answer
using $cut to see only the month
1 votes

This will work: date | cut -d' ' -f1

View answer
Sorting and calculating in linux
0 votes

reboot system boot 3.10.0-327.el7.x Wed Oct 26 15:12 - 22:43 (07:30) root :0 :0 Wed Oct 5 05:01 - 05:31 (00:29) (unknown :0 :0 Wed Oct ...

View answer
combine two csv file based on condition
0 votes

Try with this one : for i in `awk '{print $1}' A.csv`; do t1=`awk -v a="$i" '$1==a {print $3}' A.csv`; awk -F' ' -v a="$i" -v b="$t1" '$1==a {print $1" "$2" "$3" " b }' B.csv; ...

View answer
Conversion of specifc time to milliseconds using AWK
Accepted answer
0 votes

Made changes to existing code: day=$(date +%d-%b-%y) awk -v var=$day 'BEGIN{cmd="date +%s.%6N -d "} {gsub(/[][]/,"");a=varFS$1;cmd a|getline var1;print var1;}' file

View answer
Finding a character from a column
0 votes

This may help: awk -F'[|.]' '{print $7}' filename.txt

View answer
Bash script to give random extension to the filename
Accepted answer
0 votes

This will work: for fname in *.zip do CODE="$(tr -dc '[:alnum:]' </dev/urandom | head -c 6)" CODESTRING="_cod_${CODE}" YOUR mv CODE done

View answer
Give previous date as argument to shell script
0 votes

this will work: sh processFile.sh "$(date +"%Y-%m-%d" -d "yesterday")" "$(date +"%Y-%m-%d" -d "yesterday")"

View answer
Debugging Ping script
Accepted answer
0 votes

#!/bin/bash ping_targets="server1 server2 server3 server4 server5" for i in $ping_targets do ping -c 1 $i > /dev/null if [ $? -eq 0 ]; then echo "$i ping success!" > test_file ...

View answer
compare two files ignoring 1st column and print line number
0 votes

Try with this code, don't know if this will work as I don't have enough data: diff --unchanged-line-format="" --old-line-format="" --new-line-format=":%dn: %L" file1 file2 | sed 1d | cut -d':' -f2 |...

View answer
How to format output from nmap in a specific predefined format
0 votes

Try with this code: echo "Open ports are: ";nmap $HOST |awk -F'/' '/open/ {print $1}'

View answer
Have this code here, need to copy files from a directory over to mine using scripts
0 votes

Try with this one, If your filename is of specified pattern: NAME=(PATTERN1 PATTERN2) for i in ${NAMES[@]} do find PATH -name "$i" -exec cp -av {} PATH_TO_COPY \; done If your filename have ...

View answer
Shell: Check if docker container is existing
0 votes

sudo docker images -q nginx if [ $? -eq 0 ]; then echo "existing" else echo "missing" fi $? : Exit status. Every command returns an exit status or exit code, A successful command ...

View answer
How to do multi line pattern searching using awk in unix?
0 votes

Hope this is the answer you searching for: grep -oE 'department_name.*\)' file_name P.S do not know awk solution to this.

View answer
Iterate through text file and add users
0 votes

Try with this one, not tested yet: cat userlist.txt|awk -F',' '{print $1" "$3}'|while read var1 var2; do useradd $var1 -c "$var2" done Hope it work :)

View answer
How to delete everything afrer ":"
0 votes

Try with this : sed -i 's/:.*$//g' $FILE

View answer
Bash script to read list of 20+ items into array, then generate all combinations of four items from list
-1 votes

Well, try with below code getArray() { array=() while IFS= read -r line do array+=("$line") done < "$1" for i in ${!array[@]} do if [ ${#array[$i]} == ...

View answer