Help i want to change the data of one file and apend it into 2nd file.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help i want to change the data of one file and apend it into 2nd file.
# 1  
Old 12-28-2011
Java Help i want to change the data of one file and apend it into 2nd file.

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.Smilie
# 2  
Old 12-28-2011
can you show sample input file and expected output file?
# 3  
Old 12-28-2011
Try with this .. I can get the expected values ..
Code:
$ echo $cnt_rt3
23
$ nawk -v var="$cnt_rt3" -F, '{printf("%s,%s",$1,var"\n")}' rectype_3.txt
123,23
$

# 4  
Old 12-28-2011
Code:
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
# 5  
Old 12-28-2011
Hi iktamaraj.

Sir, i have given space between - and v :/

Still it is not working, will try out other solutions mentioned.
# 6  
Old 12-28-2011
Dont give the space

it should be

Code:
 
awk -v cnt="$cnt_rt3" -F, '{printf("%s,%s",$1,cnt)}' rectype_3.txt >> Rep101_$j.txt

# 7  
Old 12-28-2011
Hi Jayan,

sorry but that code change dint worked Smilie

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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Help with moving list of data to 2nd column of HTML file

Hi Team, Can you help me with writing shell script to printing the list output to 2nd column in HTML file. (2 Replies)
Discussion started by: veereshshenoy
2 Replies

2. Shell Programming and Scripting

Datestamp format 2nd change in csv file (awk or sed)

I have a csv file formatted like this: 2014-08-21 18:06:26,A,B,12345,123,C,1232,26/08/14 18:07and I'm trying to change it to MM/DD/YYYY HH:MM for both occurances. I have got this: awk -F, 'NR <=1 {print;next}{"date +%d/%m/%Y\" \"%H:%m -d\""$1 "\""| getline dte;$1=dte}1' OFS="," test.csvThis... (6 Replies)
Discussion started by: say170
6 Replies

3. Shell Programming and Scripting

Change the text in 2nd column in file

Legends, I have following entries in a file. I want to toggle the entry of 2nd column. TRUE/FALSE i tried using perl -p -i -e but the problem is, if instead of "tab" space after 1st column, there is a character or multi character space then this won't work. perl -p -i -e... (6 Replies)
Discussion started by: sdosanjh
6 Replies

4. Shell Programming and Scripting

Change data in file

Change File data Input A.txt LL725 LL725_A LL725 SIB.ra=6 LL725 LL725_B LL725 SIB.ra=11 LL726 LL726_A LL726 SIB.ra=20 LL726 LL726_B LL726 SIB.ra=6 LL726 LL726_C LL726 SIB.ra=10 Output :- LL725 LL725_A SIB.ra=6 LL725 LL725_B SIB.ra=11 LL726 LL726_A SIB.ra=20 (4 Replies)
Discussion started by: pareshkp
4 Replies

5. Shell Programming and Scripting

adding data in input file if 2nd script output SUCCESS

Hi All, how can i edit my original data and add more data if my 2nd script outputs SUCESS? ex. input file: 1.txt nik,is,the 1script.sh if 2ndscript.sh output SUCCESS then i'm going to edit my input file and add data best,pogi.. sample outputdata. nik,is,the,best,pogi 2ndscript.sh... (3 Replies)
Discussion started by: nikki1200
3 Replies

6. Shell Programming and Scripting

Execution Problems with scan and change file data content

Input file >Read_1 XXXXXXXXXXSDFXXXXXDS ASDRXXXXXTGAGTXXXXXT TGTGATXXXXXAXXXXGXXA . . Desired output file >Read_1 XXXXXXXXXXXXXXXXXXDS ASDRXXXXXTGAGTXXXXXT TGTGATXXXXXXXXXXXXXA . . (5 Replies)
Discussion started by: patrick87
5 Replies

7. Shell Programming and Scripting

Scan and change file data content problem

Input file >Read_1 XXXXXXXXXXSDFXXXXXDS (condition 1: After the last "X" per line, if the distance is less than or equal to 3 letter, replace those not "X" letter with "X") TREXXXXXXXSDFXXXXXDS (condition 2: Before the first "X" per line, if the distance is less than or equal to 3 letter,... (12 Replies)
Discussion started by: patrick87
12 Replies

8. Shell Programming and Scripting

Change file content based on data

I have a Transaction File coming into the system. In this file, in all records the relevant data is as follows- Position 1:10 -> Transaction Code Position 252:255 -> 4 digit business code Now based on these 2 fields I have to alter value in Transaction code (Position 1:10)... (6 Replies)
Discussion started by: varunrbs
6 Replies

9. Shell Programming and Scripting

loop through file to change some data

Hi, I have a file with the following data -0.00000 0.00000 0.00000 F F F 0.00000 0.00000 0.80000 F F F 0.50000 0.50000 0.60000 F F F 0.50000 0.50000 0.20000 F F F -0.00000 0.00000 0.40000 F F F I would like to change the last 3 lines from F F F to T T T. I tried looping each line but don't... (5 Replies)
Discussion started by: princessotes
5 Replies

10. Shell Programming and Scripting

To cut entire column from a file and apend it to another file as another column

file1.txt : india pakistan bangladesh japan canada africa USA srilanka Nepal file2.txt Delhi Tokyo washington I have to cut the first column of file1.txt and apend it with file2.txt as another column like this Delhi india Tokyo japan washington USA ... (4 Replies)
Discussion started by: sakthifire
4 Replies
Login or Register to Ask a Question