I get this Makefile:
LIST = foo bar
$(LIST):
echo $#
When I run make targets the outputs works as desired:
$ make foo
echo foo
foo
$ make bar
echo bar
bar
But if I concatenate a string another-, only another-foo works:
LIST = foo bar
another-$(LIST):
echo $#
$ make another-foo
echo another-foo
another-foo
$ make another-bar
make: *** No rule to make target 'another-bar'. Stop.
How can I concatenate a target to expand to all values in my variable?
The behavior you observe is standard: when writing
another-$(LIST)
make just replaces $(LIST) with its content, yielding another-foo bar.
That is, this has nothing to do with, e.g., a bash brace expression such as another-{foo,bar}.
Yet, you can achieve what you want by doing something like:
LIST = foo bar
$(addprefix another-,$(LIST)):
echo "$#"
CSV file can have data with new line . it can be with any column. Also some line can have data without any new line so it should work in all case
Sample input
ID,username,mobile,city,Message,Address,city
'11111111',TestUSer,1234567890,test,"Hi how are you? Well: we will connnect
Thanks for your time!
With Joy.
Test",Address test,City test
11111116,TestUser,1234567891,test,hello msg,Address test1,City test1
'111111167',TestUSer,1234567890,test,"Hi how are you one? Well: we will connnect
Thanks for your time!
With Joy.
Test",Address test,City test
11111112,TestUser,1234567891,test1,hello msg1,Address test2,City test2
11111113,TestUser,1234567891,test1,hello msg1,Address test2,City test2
11111114,TestUser,1234567891,test1,hello msg1,Address test2,City test2
I am using below command to read top 5 record of csv
awk -v RS='("[^"]*")?\r?\n' 'NF{ORS = gensub(/\r?\n(.)/, "\\\\n\\1", "g", RT); ++n; print} n==5{exit}' file.csv
Actual output:
ID,username,mobile,city,Message,Address,city
'11111111',TestUSer,1234567890,test,"Hi how are you? Well: we will connnect\nThanks for your time!\nWith Joy.\Test",Address test,City test
11111116,TestUser,1234567891,test,hello msg,Address test1,City test1
'111111167',TestUSer,1234567890,test,"Hi how are you one? Well: we will connnect\nThanks for your time!\nWith Joy.\nTest",Address test,City test
11111112,TestUser,1234567891,test1,hello msg1,Address test2,City test2
11111113,TestUser,1234567891,test1,hello msg1,Address test2,City test2
11111114,TestUser,1234567891,test1,hello msg1,Address test2,City test2
Wanted output:
ID,username,mobile,city,Message,Address,city
'11111111',TestUSer,1234567890,test,"Hi how are you? Well: we will connnect\nThanks for your time!\nWith Joy.\Test",Address test,City test
11111116,TestUser,1234567891,test,hello msg,Address test1,City test1
'111111167',TestUSer,1234567890,test,"Hi how are you one? Well: we will connnect\nThanks for your time!\nWith Joy.\nTest",Address test,City test
11111112,TestUser,1234567891,test1,hello msg1,Address test2,City test2
With your shown samples only, could you please try following awk code. Written and tested with GNU awk. Make use of RS record separator and then substitute globally to nullify new lines in RT, then print the lines accordingly.
awk -v RS='"[^"]*"' '{gsub(/\n/,"\\n",RT);ORS=RT} 1' Input_file
To get first 10 records, try following:
awk -v RS='"[^"]*"' '{gsub(/\n/,"\\n",RT);ORS=RT} 1' Input_file | head -10
Warning: Self promotion ahead!
I wrote an awk-like utility called tawk that uses tcl as its scripting language, and has a mode that reads CSV data without having to hack around with regular expressions to handle records with embedded newlines and quotes (This feature was actually my major inspiration for it).
Using it:
$ tawk -csv 'line {$NR <= 5} { puts [regsub -all {\n+} $F(0) "\\n"]; if {$NR == 5} exit }' input.csv
ID,username,mobile,city,Message,Address,city
'11111111',TestUSer,1234567890,test,"Hi how are you? Well: we will connnect\nThanks for your time!\nWith Joy.\nTest",Address test,City test
11111116,TestUser,1234567891,test,hello msg,Address test1,City test1
'111111167',TestUSer,1234567890,test,"Hi how are you one? Well: we will connnect\nThanks for your time!\nWith Joy.\nTest",Address test,City test
11111112,TestUser,1234567891,test1,hello msg1,Address test2,City test2
I have a makefile, 1.mk with following content:
#!make
aa := x
bb := y
cc := z
export
include abc.mk
all:
#echo $(chk1)
And another makefile, abc.mk with following content:
#!make
chk1 := $(shell set -o posix; set | awk -F "=" 'BEGIN{ORS=" "}1 $$1~/[a-zA-Z_][a-zA-Z0-9_]*/ {print $$1}')
chk2 := $(shell env &> pqr)
export
When I check, none has the makefile-variables:
> make all -f 1.mk | grep aa
> grep 'aa' pqr
Thus I can say, compile time shell does not have makefile variables. I want a way to access all makefile variables in compile-time shell.
Constraint: I do not know variable names beforehand to write code in following manner:
chk2 := $(shell export aa=$(aa); env &> pqr)
As far as I understand the way make exports make variables, it does so only in recipes, not in the shells invoked with the shell function. You can test this with, for instance:
$ cat Makefile
aa := x
export
chk := $(shell echo $$aa)
.PHONY: all
all:
#printf 'in shell function: aa = $(chk)\n'
#printf 'in recipe: aa = %s\n' "$$aa"
$ make
in shell function: aa =
in recipe: aa = x