NR Versus FNR In Awk Scripts

I have got a data file that contains 22 records.

When i write an awk script to compute the number of records, i print the value of NR variable. Why does it show 23 instead of 22?

I get the same output from FNR variable also. So what is the difference between NR and FNR variable?

In the text i found that
NR: gives number of records read- record number in the current file
FNR: file number of records read- a record number in the current file


Similar Content



About The Installation Of Awstats

I follow the below URL to install awstats .

Code:
http://thelinuxfaq.com/90-how-to-install-and-configure-awstats-in-centos-fedora-rhel

everything seems works fine , the second last step works fine.
Code:
From data in log file "/var/log/httpd/access_log"...
Phase 1 : First bypass old records, searching new record...
Searching new records from beginning of log file...
Phase 2 : Now process new records (Flush history on disk after 20000 hosts)...
Jumped lines in file: 0
Parsed lines in file: 77
 Found 0 dropped records,
 Found 0 comments,
 Found 0 blank records,
 Found 0 corrupted records,
 Found 0 old records,
 Found 77 new qualified records.

then I tried the below URL , it shows nothing , would advise what is the possible reason ? how can I do the trouble shooting ? thanks
Code:
http://mydomain.com/awstats/awstats.pl?config=mydomain.com

Calculation Using Variable Inside Variable

I have some variables which have stored numerical values like
Quote:
A1=10 A2=20 A3=25
B1=10 B2=15 B3=12 and so on
As well as another set of variables which stored these variables like
Quote:
var1=A1 var2=A2 var3=A3
var4=B1 var5=B2 var6=B3 and so on
I have to calculated things using second set of variable.
In the script, there is line
Code:
read number

user will enter number manually, suppose 500
I have to calculate using
Code:
expr 500 \* ${$var1} / 100

and output of this multiplied by
Code:
expr $above_output \* ${$var2} /100

and output of this multiplied by
Code:
expr $above_output \* ${$var3} /100

But not able to deal with two levels of variable. The calculation will be hard when it comes for three level and four level.

Please help.

Checking Presence Of A File Identified/ Addressed By A Variable

hi,

I am newbie in Linux shell scripting.Can anybody help me to check the presence of file identified by variable in Shell scripting?

For example: I am reading the content of a file using while command as below:
"while read -r line
do
code block
done < file_name"

Now in this case every line in file gets stored in the variable 'line' one by one.Problem here is every line in the file is nothing but the file_path of another file say xyz.txt and I am checking presence of this xyz.txt file using below command:
if [-f $line]
as 'line' is the variable which stores file path of xyz.txt but it is not working. It is unable to check the presence of this xyz.txt file as i am addressing it with the variable 'line'.

Please help me.Thanks in advance.

Measuring Disk Performance With Clustered IOzone

Dear all,
I don't know how I can figure this problem out.

I tried to execute iozone with clustered mode but it didn't work. It stalled after executing the last line (see below!)
What do you think the problem is?
Please let me know if you have similar experience to me.

Best regards,
Jeongsook.

----------

[root@host current]# ./iozone -i0 -i1 -R -I -+n -w -r 128k -s 1G -+m node.lst -t 4

Run began: Mon Apr 13 17:07:21 2015

Excel chart generation enabled
O_DIRECT feature enabled
No retest option selected
Setting no_unlink
Record Size 128 KB
File size set to 1048576 KB
Network distribution mode enabled.
Command line used: ./iozone -i0 -i1 -R -I -+n -w -r 128k -s 1G -+m node. lst -t 4
Output is in Kbytes/sec
Time Resolution = 0.000001 seconds.
Processor cache size set to 1024 Kbytes.
Processor cache line size set to 32 bytes.
File stride size set to 17 * record size.
Throughput test with 8 processes
Each process writes a 1048576 Kbyte file in 128 Kbyte records

******** Content of node.lst
[root@lamap10 current]# cat node.lst
129.254.XXX.XXX /root/iozone3_420/src/current /root/iozone3_420/src/current/iozone /mnt/vdi/iozone/129_254_XXX_XXX/DUMMY.1
129.254.XXX.XXX /root/iozone3_420/src/current /root/iozone3_420/src/current/iozone /mnt/vdi/iozone/129_254_XXX_XXX/DUMMY.2
129.254.XXX.XXX /root/iozone3_420/src/current /root/iozone3_420/src/current/iozone /mnt/vdi/iozone/129_254_XXX_XXX/DUMMY.3
129.254.XXX.XXX /root/iozone3_420/src/current /root/iozone3_420/src/current/iozone /mnt/vdi/iozone/129_254_XXX_XXX/DUMMY.4

Sending Mails With Port Number 587 Bash Script Help

Hi All,
We have some shell scripts which will send emails about backup, alerts etc using mail command. Example.
Code:
echo "Test Mail" | mail -s "Test" me@mydomain.com

I guess the above command just connect port number 25 of our mail server even if we do not define any port number. Now I would like add smtp port number as 587 in all of the bash scripts. I googled for this but could not get whatever I am expecting. So expecting your kind reply to define smtp port number as 587 in all of the bash scripts.

Thanks in advance.

TORA Simulation Segmentation Fault For Nodes <= 100 In NS-2.35 On Ubuntu 12.04

i am trying to simulate Tora for 50, 110, 170 and 200 number of nodes. but for 50 number of nodes trace file become so large that it does give segmentation fault error when i tried to extract results with awk file. for 100 number of nodes simulation never comes an end. please help me... if m missing something ...

How To Extract Data Between A Matched Strings In A File

Hi All,
I got stuck when i am trying to extract the data between a matched strings in a file which contains a million records with \t is the field seperator. i am getting that matched_string in only one particular field(5 field).

ex: fiel_name:siva.txt

record_1: a b c d _bb_vid:dfndjgddgn~~~ e f g
record_2: h g e f _bb_vid:kdjgfkdhjk~~~ k h d

like this lakhs of records will be there. i want add the result set into end of the file with \t as field seperator.

estimated_out_put:
record_1: a b c d _bb_vid:dfndjgddgn~~~ e f g dfndjgddgn
record_2: h g e f _bb_vid:kdjgfkdhjk~~~ k h d kdjgfkdhjk

please help me guys.

Help Modifying Text With User Input

Hello,

I apologize in advance for my limited UNIX scripting knowledge. I am new to it and really want to learn.

I am trying to write a bash script that updates a config file based on user input.

What is the best method for accomplishing this? I need it to prompt the user for two variables, find the location in the config file, and insert new text with the two variables.

I was thinking I could use sed to find the text in the config file where the new text must be inserted before and replace it with the new text, two variables, and same ending text as before. Example:

echo "1st variable?"
read variable1

echo "2nd variable?"
read variable2

sed -e "s|<the spot in the config file that needs new config>|sometext...$variable2_somemoretext...$variable1\n<the spot in the config file that needs new config>|g" config > config2


This works except variable2 is not inserted into the replace string, only variable1 is. This is the result in config2:

sometext..._somemoretext...$variable1
<the spot in the config file that needs new config>


If anyone can tell me why variable2 isn't working in the sed replace string, or if there's a much better way for accomplishing what I'm after, I'd appreciate any help I can get.

Record Buffer Provided By Awk

we do have a record buffer in awk utility that holds one complete record of a data file.

I want to know that if record buffer changes during script processing, then when are these changes reflected back to the data file?

Are they reflected immediately or is there an in-built mechanism available to schedule this change?

Help Mounting A CD-R/DVD-R, Then Using Dd To Write To Them.

I can't seem to mount a CD-R or DVD-R, doesn't matter if it is blank or not.
However, when I use a program such as Brasero, I am able to write to them. I cannot use dd to write to them.

This is the output of trying to mount/unmount.
Code:
root@delarocha-> mount /dev/sr0 /media/cd
mount: /dev/sr0 is write-protected, mounting read-only
mount: wrong fs type, bad option, bad superblock on /dev/sr0,
       missing codepage or helper program, or other error
       In some cases useful info is found in syslog - try
       dmesg | tail or so.

root@delarocha-> umount /dev/sr0
umount: /dev/sr0: not mounted
root@delarocha-> umount /media/cd
umount: /media/cd: not mounted
root@delarocha-> umount /media/cdrom
umount: /media/cdrom: not mounted

dmesg | tail
Code:
root@delarocha-> dmesg | tail
[ 1536.299777] sr 1:0:0:0: [sr0]  
[ 1536.299804] Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE
[ 1536.299809] sr 1:0:0:0: [sr0]  
[ 1536.299814] Sense Key : Illegal Request [current] 
[ 1536.299820] sr 1:0:0:0: [sr0]  
[ 1536.299824] Add. Sense: Logical block address out of range
[ 1536.299829] sr 1:0:0:0: [sr0] CDB: 
[ 1536.299832] Read(10): 28 00 00 00 00 00 00 00 01 00
[ 1536.299846] end_request: I/O error, dev sr0, sector 0
[ 1536.299915] EXT4-fs (sr0): unable to read superblock

I don't think it can be anything wrong with the disk, since it is a untouched disk.
Note: The results of everything(apart from dmesg I would assume), are the same for a CD-R and DVD-R

This is what I get while trying to dd a .iso and .mp4, respectively.

Code:
web@delarocha-> dd if=/dev/sr0 of=~/Downloads/xubuntu-14.04.1-desktop-amd64.iso
0+0 records in
0+0 records out
0 bytes (0 B) copied, 0.000377316 s, 0.0 kB/s

Code:
web@delarocha-> dd if=/dev/sr0 of=~/Videos/The\ Hobbit/The\ Hobbit\ The\ Desolation\ of\ Smaug.mp4
0+0 records in
0+0 records out
0 bytes (0 B) copied, 0.000377179 s, 0.0 kB/s

uname -a
Code:
Linux delarocha 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt2-1 (2014-12-08) x86_64 GNU/Linux

When I used lsblk when I close the disk tray, it shows it mounted.
Code:
sr0                     11:0    1     2K  0 rom

But after I use the dd command to write the .iso, it disappears.

Here is my /etc/fstab
Code:
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
/dev/mapper/delarocha-root /               ext4    errors=remount-ro 0       1
# /boot was on /dev/sda1 during installation
UUID=5bbedec0-6e3d-4185-91e0-292a72585908 /boot           ext2    defaults        0       2
/dev/mapper/delarocha-swap_1 none            swap    sw              0       0
/dev/sr0        /media/cdrom0   udf,iso9660 user,noauto     0       0
/dev/sdb1       /media/usb0     auto    rw,user,noauto  0       0

I have also tried replacing /dev/sr0 in the above commands with /media/cdrom0.