How to remove space/TAB from command output
awk '/^MemTotal:/ {print $2}' /proc/meminfo
Output (e.g.), unit: kB:
3095532
Or:
grep -oP "^MemTotal: *\K[^ ]+" /proc/meminfo
Output (e.g.), unit: kB:
3095532
Remove blank spaces comm output
Given this input and comm
output:
$ cat file1
YAL002W
YAL003W
YAL008W
$ cat file2
YAL004W
YAL005C
YAL008W
YAL011W
$ comm file1 file2
YAL002W
YAL003W
YAL004W
YAL005C
YAL008W
YAL011W
This will do what you asked for:
$ cat tst.awk
BEGIN { FS=OFS="\t" }
{
colNr = NF
rowNr = ++rowNrs[colNr]
val[rowNr,colNr] = $NF
numCols = (colNr > numCols ? colNr : numCols)
numRows = (rowNr > numRows ? rowNr : numRows)
}
END {
for (rowNr=1; rowNr<=numRows; rowNr++) {
for (colNr=1; colNr<=numCols; colNr++) {
printf "%s%s", val[rowNr,colNr], (colNr<numCols ? OFS : ORS)
}
}
}
.
$ comm file1 file2 | awk -f tst.awk
YAL002W YAL004W YAL008W
YAL003W YAL005C
YAL011W
but of course you could just skip the call to comm
and use awk right off the bat:
$ cat tst.awk
BEGIN { FS=OFS="\t" }
NR==FNR {
file1[$0]
next
}
{
if ($0 in file1) {
colNr = 3
delete file1[$0]
}
else {
colNr = 2
}
rowNr = ++rowNrs[colNr]
val[rowNr,colNr] = $0
}
END {
for (v in file1) {
colNr = 1
rowNr = ++rowNrs[colNr]
val[rowNr,colNr] = v
}
numRows = (rowNrs[1] > rowNrs[2] ? rowNrs[1] : rowNrs[2])
numRows = (numRows > rowNrs[3] ? numRows : rowNrs[3])
numCols = 3
for (rowNr=1; rowNr<=numRows; rowNr++) {
for (colNr=1; colNr<=numCols; colNr++) {
printf "%s%s", val[rowNr,colNr], (colNr<numCols ? OFS : ORS)
}
}
}
.
$ awk -f tst.awk file1 file2
YAL002W YAL004W YAL008W
YAL003W YAL005C
YAL011W
Bash - How to remove all white spaces from a given text file?
$ man tr
NAME
tr - translate or delete characters
SYNOPSIS
tr [OPTION]... SET1 [SET2]
DESCRIPTION
Translate, squeeze, and/or delete characters from standard
input, writing to standard output.
In order to wipe all whitespace including newlines you can try:
cat file.txt | tr -d " \t\n\r"
You can also use the character classes defined by tr (credits to htompkins comment):
cat file.txt | tr -d "[:space:]"
For example, in order to wipe just horizontal white space:
cat file.txt | tr -d "[:blank:]"
How to remove space from string?
Try doing this in a shell:
var=" 3918912k"
echo ${var//[[:blank:]]/}
That uses parameter expansion (it's a non posix feature)
[[:blank:]]
is a POSIX regex class (remove spaces, tabs...), see http://www.regular-expressions.info/posixbrackets.html
Get rid of spaces and tabs in wmic output
The output from WMIC is unicode, your "spaces" are nulls from the two bytes unicode characters in file. Try with
wmic logicaldisk get caption,description,volumename | find /v "" >>"C:\out.log"
Related Topics
Omnibus or Source - Can't Decide Which One to Use for Gitllab Backup/Restore
In Shellscript Assign Variable Based on Curl Output
Sort a Find Command to Respect a Custom Order in Unix
Bash Concurrent Jobs Gets Stuck
Gitlab-Ci Alpine Image: Host Key Verification Failed
Linux Shell Scripting: How to Remove Final Numbers in a Word List File
Git Status Between Windows and Linux Does Not Agree
Implementation of Syscall() on Arm-Oabi. What Is "Svc #0X900071"
How to Get The Process Id of Command Executed in Bash Script
Ssh Environment Variable for Sudo Access
Change The Rlimit_Nproc in Linux
Error While Building Pjsip in Linux