I’m trying to:
- Taking a file/directory listing, and replacing all spaces >1 (NOT \t) with ‘#’ for all files modified within the last 30 minutes.
Example output of: find / -mmin -30 -ls
310116371 0 -r--r--r-- 1 root root 0 Jan 14 0814 /proc/4732/wchan
310116373 0 -r--r--r-- 1 root root 0 Jan 14 0814 /proc/4732/schedstat
310116374 0 -r--r--r-- 1 root root 0 Jan 14 0814 /proc/4732/cpuset
310116383 0 -r--r--r-- 1 root root 0 Jan 14 0814 /proc/4732/oom_score
310116384 0 -rw-r--r-- 1 root root 0 Jan 14 0814 /proc/4732/oom_adj
310116382 0 -rw-r--r-- 1 root root 0 Jan 14 0814 /proc/4732/loginuid
310116416 0 -r-------- 1 root root 0 Jan 14 0814 /proc/4732/limits
310116418 0 -r--r--r-- 1 root root 0 Jan 14 0814 /proc/4732/io
What I want:
310116371#0#-r--r--r--#1#root#root#0#Jan 14 0814#/proc/4732/wchan
Specifically, I want to use {awk, sed, tr} to replace spaces where the amount of space is greater than 1. The only problem is, there is a single space after the timestamp arg for the directory listing…
Is there a computational method which exists today which can to this?
- Log file being parsed consists of ~26k entries
- Output being pasted into an .XLS file
What I’ve tried:
find / -mmin -5 -ls | awk '{gsub(/s+/,"#",$0); print;}'
find / -mmin -5 -ls | awk '{gsub(/[' ']+/,"#")}1'
find / -mmin -5 -ls | awk '{gsub(/[" "]+/,"#")}1'
find / -mmin -5 -ls | sed "s/^ *//;s/ *$//;s/ \{1,\}/#/g"
find / -mmin -5 -ls | awk -D '{gsub([ +],"#",$0); print;}'
find / -mmin -5 -ls | awk '{gsub(/\t/,"#",$0); print;}'
The problem:
– The output of find / -mmin -5 -ls is not {tab, comma} delimited by default
Any suggestions about where am I going wrong?
This does the trick for me
awk 'gsub(/\s+/,"#")':Or
awk 'gsub(/\s{2,}/,"#")'for:Edit:
How about just setting the
OFSvariable: