简体   繁体   中英

To add column name in files using awk

This is my command:

awk \
  -v DATE="$(date +"%d%m%Y")" \
  -F"," \
  'BEGIN{OFS=","} NR>1{ gsub(/"/,"",$1); print > "Assignment_"$1"_"DATE".csv"}' \
  Test_01012020.CSV

I manage to get this but I want included my column name

As per my understanding of your question, you imply that you want to include the headers for the file. If this is so, you can do that by using sed command. You can add this command at the end of your command using a pipe separator.

sed '1i header_value_1,header_value2,.....' 

and so on as many headers you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM