Hi All,
Please help i have written an ksh script, where i am actually take count of lines in one file and want to update this count to 2nd field of a new file and apend the this into an existing file.
Note the below script is in for loop
-------- I am apending few records in a file ($file) below --
cat /mi/int/workingdir/$file >> Rep101_$j.txt
---taking count of records in the file
cnt_rt3=`wc -l <$file` >
------ i want to put this count in 2nd field's place of rectype_3.txt and apend this in the file Rep101_$j.txt
awk - v cnt=$cnt_rt3 -F"," '{printf("%s,%s",$1,cnt)}' rectype_3.txt >> Rep101_$j.txt
----------- When i am trying to do above, i am getting below error.
+ awk - v cnt= 9 -F, {printf("%s,%s",$1,cnt)} rectype_3.txt
+ 1>> Rep101_10.txt
Syntax Error The source line is 1.
The error context is
>>> - <<<
awk: 0602-500 Quitting The source line is 1.
------------- Please help me, i need to finish the script asap n deliver it to my supervisor.:wall:
can you show sample input file and expected output file?
Try with this .. I can get the expected values ..
$ echo $cnt_rt3
23
$ nawk -v var="$cnt_rt3" -F, '{printf("%s,%s",$1,var"\n")}' rectype_3.txt
123,23
$
awk - v cnt=$cnt_rt3 -F"," '{printf("%s,%s",$1,cnt)}' rectype_3.txt >> Rep101_$j.txt
you have space in between the - and v
Hi iktamaraj.
Sir, i have given space between - and v
Still it is not working, will try out other solutions mentioned.
Dont give the space
it should be
awk -v cnt="$cnt_rt3" -F, '{printf("%s,%s",$1,cnt)}' rectype_3.txt >> Rep101_$j.txt
Hi Jayan,
sorry but that code change dint worked
Vivek, file should be something like this
Rep101_1
1 Amit mem011 gupta 90099
2 Vikash mem011 gupta 90099
Count of the file is --2
rectype3 has values
3 48
--------- I want to change the value 48 to count of Rep101_1 (i.e. 2)
and apend in Rep101_1
------- Rep101_1 becomes
1 Amit mem011 gupta 90099
2 Vikash mem011 gupta 90099
3 2
Please help
If your rectype3 file is not comma separated, then why are using -F,
. Modified the code and its working now for me ..
$ nawk -v var="$cnt_rt3" '{printf("%s %s",$1,var"\n")}' rectype_3.txt >> Rep101_1