1

How i want to split content to multiple files using date format as following below:

Test_<ID name><ddmmyyyy>.CSV

How can I split according to the format?

as before this i use:

awk -F"," 'NR>1 {print > "Test_<ID name><ddmmyyyy>.CSV_"$1".csv"}' Original.CSV

Edit

I got there with

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

but then I want to include my column name too. How?

J. Chomel
  • 8,193
  • 15
  • 41
  • 69
FARAH
  • 33
  • 1
  • 7
  • @j. chomel thanks but i want the file in format : Test_.CSV – FARAH Feb 17 '17 at 08:39
  • 1
    Possible duplicate of [How to remove double quotes using awk](http://stackoverflow.com/questions/42338647/how-to-remove-double-quotes-using-awk) – Akshay Hegde Feb 20 '17 at 08:53

1 Answers1

0

You could try using variables from the shell in your thing:

_DATE=` date '+%d%m%Y' `
_ID=my_value
F_EXT=${_ID}${_DATE}
# here "var" is set to the value defined from the shell "F_EXT"
awk -v var=${F_EXT} -F"," 'NR>1 {print > "Test_" var ".CSV_"$1".csv"}' Original.CSV

(I didn't get where you were taking your "ID name", so here it's my_value)

Edit

If you want to include your column name, then read it with the case when NR==1:

awk -v DATE="$(date +"%d%m%Y")" -F"," 'BEGIN{OFS="," } NR==1 {COLUMN_NAME=$1} NR>1 { gsub(/"/,"",$1); print > "Assignment_"$1"_"COLUMN_NAME"_"DATE".csv"}' a.txt
Community
  • 1
  • 1
J. Chomel
  • 8,193
  • 15
  • 41
  • 69
  • @J.chomel..actually i want to split file into multiple file then save the file in format example Test.CSV..but then how can i create such as the format? I still cannot find it..i want to use awk technique..i already find out how to split but i could not find how to split in format? – FARAH Feb 20 '17 at 01:27
  • @FARAH, its so very unclear... Could you update your original post (OP) with input format and expected output format? Is it CSV format, e.g. fields from original file separated with `,`? But if your input is already CSV, then you just add the line... Or do you want the header line repeated in each file? – J. Chomel Feb 20 '17 at 08:35
  • I got already by using this command **awk -v DATE="$(date +"%d%m%Y")" -F"," 'BEGIN{OFS=","}NR>1 { gsub(/"/,"",$1); print > "Assignment_"$1"_"DATE".csv"}' Test_01012020.CSV** but then I want to include my column name too. How? @J. Chomel – FARAH Feb 20 '17 at 08:39