remove ^M characters from file using sed
Use tr: tr -d ‘^M’ < inputfile (Note that the ^M character can be input using Ctrl+VCtrl+M) EDIT: As suggested by Glenn Jackman, if you’re using bash, you could also say: tr -d $’\r’ < inputfile
Use tr: tr -d ‘^M’ < inputfile (Note that the ^M character can be input using Ctrl+VCtrl+M) EDIT: As suggested by Glenn Jackman, if you’re using bash, you could also say: tr -d $’\r’ < inputfile
awk ‘{SUM+=$3}END{print SUM}’ where $3 represent value of column 3
Use the int function to get the integer part of the result, truncated toward 0. This produces the nearest integer to the result, located between the result and 0. For example, int(3/2) is 1, int(-3/2) is -1. Source: The AWK Manual – Numeric Functions
The NF variable is set to the total number of fields in the input record. So: echo “a b c d” | awk –field-separator=” ” “{ print NF }” will display 4 Note, however, that: echo -e “a b c d\na b” | awk –field-separator=” ” “{ print NF }” will display: 4 2 Hope … Read more
With awk : awk ‘$1!=p+1{print p+1″-“$1-1}{p=$1}’ file.txt explanations $1 is the first column from current input line p is the previous value of the last line so ($1!=p+1) is a condition : if $1 is different than previous value +1, then : this part is executed : {print p+1 “-” $1-1} : print previous value … Read more
You can use gsub function: awk -F’,’ ‘{gsub(/”/, “”, $2); print “set”, $2, $3}’ testme.csv set 1211274723 “0” set 1211292921 “0” set 1211295793 “0” set 1211310146 “0” set 1211310310 “0” set 1211315271 “0” set 1211318203 “0” set 1211323658 “0” set 1211329224 “0” set 1211330064 “0”
awk ‘{ if ($4 >= 1 && $4 <= 10) print $1 }’ sample.txt
You can use the command line tool dos2unix dos2unix input Or use the tr command: tr -d ‘\r’ <input >output Actually, you can do the file-format switching in vim: Method A: :e ++ff=dos :w ++ff=unix :e! Method B: :e ++ff=dos :set ff=unix :w EDIT If you want to delete the \r\n sequences in the file, … Read more
Using sed: $ var=server@10.200.200.20:/home/some/directory/file $ echo $var | sed ‘s/.*://’ /home/some/directory/file
Use system from within awk: awk ‘{ system(“openssl s_client -connect host:port -cipher ” $1) }’ ciphers.txt