Count string at header.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Count string at header.
# 8  
Old 04-20-2007
Thanks anbu23,
i just get it, and your post give me a shorter script, thanks buddy.
the awk script at first was created earlier to modified different spool file. So, i thought editing it would be less time consuming. but i wrong. final solution just come out after referring to your post. Thanks again.

Regards,
Helmi
# 9  
Old 04-25-2007
hi,
sorry, again i noticed there are white spaces (or spaces) in the header text.
i used anbu23's example script and edited. and this is the result:
Code:
1NBI01820070425*****999153243NBI01820070425153243.txt
2C501129114308 2007032220060621+        .00MYR22A0140002                        
2C501039413101 2007032220060621+        .00MYR22A0140002                        
2C501039413209 2007032220060621+        .00MYR22A0140002

* indicated spaces, which maybe, from `wc -l`, i guessed. It also hold 8(plus 999) digits, which i prefer 7 only (****999).

the white spaces can be replace by 0 which mean if seven digits, it will be like this 0000999 and if 1000, like this 0001000

here is the script which is from anbu23, i made small editing.
Code:
noseq=`get_inc_file_seq2.sh`
date=`date +%C%y%m%d`
time=`date +%H%M%S`
fdate=`date +%C%y%m%d%H%M%S`

no_of_records=$( wc -l< irate_spool.lst*)
hdr_rec="1NBI${noseq}${date}${no_of_records}${time}NBI${noseq}${fdate}.txt"
sed "1 i\\
$hdr_rec" irate_spool.lst* > NBI${noseq}${fdate}.txt
#mv irate_spool.lst* $dir/history2

Any help,solution to this small matter, i newbie in awk and sed, so, thanks in advances

regards,
Helmi.
# 10  
Old 04-25-2007
Change
Code:
no_of_records=$( wc -l< irate_spool.lst*)

to
Code:
no_of_records=$( printf "%07d" $( wc -l< irate_spool.lst*) )

# 11  
Old 04-25-2007
Thank alot...anbu23.
it work well, and i must keep an eye of the output.
as i am trying this sed, it come to cross my mind that why,
Code:
sed "1 i\\
$hdr_rec" irate_spool.lst* > NBI${noseq}${fdate}.txt

instant of writing it on the same line?
Code:
sed "1 i\\$hdr_rec" irate_spool.lst* > NBI${noseq}${fdate}.txt

at 1st i tried it and there are errors.

regards,
Helmi
# 12  
Old 04-25-2007
Thank alot...anbu23.
it work well, and i must keep an eye of the output.
as i am trying this sed, it come to cross my mind that why,
Code:
sed "1 i\\
$hdr_rec" irate_spool.lst* > NBI${noseq}${fdate}.txt

instant of writing it on the same line?
Code:
sed "1 i\\$hdr_rec" irate_spool.lst* > NBI${noseq}${fdate}.txt

at 1st i tried it and there are errors.

regards,
Helmi
# 13  
Old 04-25-2007
Quote:
Originally Posted by Helmi
Thank alot...anbu23.
it work well, and i must keep an eye of the output.
as i am trying this sed, it come to cross my mind that why,
Code:
sed "1 i\\
$hdr_rec" irate_spool.lst* > NBI${noseq}${fdate}.txt

instant of writing it on the same line?
Code:
sed "1 i\\$hdr_rec" irate_spool.lst* > NBI${noseq}${fdate}.txt

at 1st i tried it and there are errors.

regards,
Helmi
Syntax of insert command
Code:
[line-address]i\
text

If you use single quotes you can use single backslash
Code:
sed '1 i\
$hdr_rec' irate_spool.lst* > NBI${noseq}${fdate}.txt

# 14  
Old 04-25-2007
The way anbu first posted the sed insert command allows $hdr_rec substitution, which is correct. Using single quotes would turn it off. Then line 1 would literally be:

$hdr_rec
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep a string and count following lines starting with another string

I have a large dataset with following structure; C 0001 Carbon D SAR001 methane D SAR002 ethane D SAR003 propane D SAR004 butane D SAR005 pentane C 0002 Hydrogen C 0003 Nitrogen C 0004 Oxygen D SAR011 ozone D SAR012 super oxide C 0005 Sulphur D SAR013... (3 Replies)
Discussion started by: Syeda Sumayya
3 Replies

2. Shell Programming and Scripting

Compare file1 header count with file2 line count

What I'm trying to accomplish. I receive a Header and Detail file for daily processing. The detail file comes first which holds data, the header is a receipt of the detail file and has the detail files record count. Before processing the detail file I would like to put a wrapper around another... (4 Replies)
Discussion started by: pone2332
4 Replies

3. UNIX for Dummies Questions & Answers

File Row Line Count without Header Footer

Hi There! I am saving the file count of all files in a directory to an output file using: wc -l * > FileCount.txt I get: 114 G4SXORD 3 G4SXORH 0 G4SXORP 117 total But this count includes header and footer. I want to subtract 2 from the count and get ... (7 Replies)
Discussion started by: gagan8877
7 Replies

4. Programming

Error with the string.h header

I get this error when I try to compile following C program #include <stdio.h> #include <strings.h> #define LEN 80 int main(void) { int mess, flag = 1; int first = 0, last = 0; printf("Enter a message: "); gets(mess); if (strlen(mess) > LEN) ... (3 Replies)
Discussion started by: solaris_user
3 Replies

5. Shell Programming and Scripting

Need awk help to print specific columns with as string in a header

awk experts, I have a big file of 4000 columns with header. Would like to print the columns with string value of "Commands" in header. File has "," separator. This file is on ESX host with Bash. Thanks, Arv (21 Replies)
Discussion started by: arv_cds
21 Replies

6. Shell Programming and Scripting

Extract columns where header matches a given string

Hi, I'm having trouble pulling out columns where the headers match a file of key ID's I'm interested in and was looking for some help. file1.txt I Name 34 56 84 350 790 1215 1919 7606 9420 file2.txt I Name 1 1 2 2 3 3 ... 34 34... 56 56... 84 84... 350 350... M 1 A A A A... (20 Replies)
Discussion started by: flotsam
20 Replies

7. Shell Programming and Scripting

Header as is.. trailer count

i have .DAT file FILE1.DAT 1200910270040625 2123456789 J123456 ABC 2123456789 K123456 ABC 2222222222 L123456 DEF 2333333333 M12345 GHI 30000004 My outfile FILE2.TXT should have like this, I need the header value as ie (1200910270040625 ) body rows remove the duplicate rows and the... (2 Replies)
Discussion started by: kshuser
2 Replies

8. Shell Programming and Scripting

Inserting a String in a file header.

Dear all, I have a file created in the name sample.txt in UNIX with header and footer. How to insert a required string (for example "FILE1") in the header part after the file has been created. What kind of command can i use to do the same. Thanks in advance Hari (3 Replies)
Discussion started by: Hari123
3 Replies

9. UNIX for Dummies Questions & Answers

Checking the header and trailer for a given string and if not found, exit out of the

hi, How to check a given file for a string and if it's not found, exit out ofthe script? e.g. a file Test123 is there whose header begins with #bt and trailer begins with #ed. I have to check if the header and trailer matches as above and if not, exit out of the script. How can we do it in... (2 Replies)
Discussion started by: er_ashu
2 Replies

10. Shell Programming and Scripting

Count No of Records in File without counting Header and Trailer Records

I have a flat file and need to count no of records in the file less the header and the trailer record. I would appreciate any and all asistance Thanks Hadi Lalani (2 Replies)
Discussion started by: guiguy
2 Replies
Login or Register to Ask a Question