shell - How to convert the column to row data using bash script and create the csv file -


have data in text file (input data) want convert in csv file. how can create in below format in bash script?

  • input data

    • a=1
    • b=2
    • c=3
    • d=4
  • output data (csv file data)

    • a,b,c,d
    • 1,2,3,4

without array

i=0  while ifs='=' read -r key value      echo "$key"     echo "$value"     echo "$i"     i=$((i+1))  done < "stats.txt" 

with array:

 i=0  j=0  while ifs='=' read -r key value    echo arraykey[`$i`]="$key"  echo arrayval[`$j`]="$value"  i=`$((i+1))`  j=`$((j+1))`  done < status.txt         

in awk:

$ awk '                                  # awk begin { fs="=";ofs=",";start=1 }         # separators nr>=start && $0!="" {                    # define start line , remove empties     # sub(/\r/,"",$nf)                   # uncomment remove windows line endings     for(i=1;i<=nf;i++)                   # cols          a[i]=a[i] (nr==start?"":ofs) $i  # gather     } end {                                    # in end     for(j=1;j<i;j++)                     # ..         print a[j]                       # outputed }' file a,b,c,d 1,2,3,4 

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -