Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strip whitespaces in AWK

Tags:

linux

bash

awk

I have tried to remove all the white spaces but it's not taking it.

awk -F, -v OFS=", " 'NR==1 {
        print $0,"FILENAME,DATE_LOADED,TEST";
        next
      }
      {                              
        line=$0
        key=echo "${11//[[:space:]]/}" "${12//[[:space:]]/}" "${57//[[:space:]]/}"
        key | getline
        k=$0
        cmd="md5 <<<"k
        cmd | getline
        md5sum=$0
        print line, ENVIRON["FILE"], ENVIRON["ISODATE"], md5sum
}' $FILE > $NAME"_ready.csv"

If I try this it throws errors. I tried all options and really at a loss here.

key=echo $11$12$57 | tr -d
like image 809
arve Avatar asked Oct 03 '22 14:10

arve


1 Answers

awk '{gsub(" +","");print $0}' test.text

If you want only awk based solution then this one liner will remove all the spaces from the file.

like image 152
Gaurav Pant Avatar answered Oct 11 '22 21:10

Gaurav Pant