Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Difficulty to create .txt file from loop in bash Post 303044864 by RudiC on Thursday 5th of March 2020 12:34:41 PM
Old 03-05-2020
"But it doesn't works..." is not something people can start working / analysing / debugging upon. Be more precise / descriptive; include error messages, warnings, non-satisfying output, etc.



Try (assuming mount points are unique)

Code:
awk -F\; '
        {MTH = substr($1,1,7)
         SUM[MTH,$2] += $3
         MNT[MTH,$2]   = $4
        }
END     {for (s in SUM)         {n = split (s, T, "[;/]")
                                 print s, SUM[s], MNT[s]  >  (T[n] ".txt")
                                }
        }
' OFS=\; SUBSEP=\; file[123]
cf *.txt

---------- hd1.txt: ----------

2020-03;/dev/hd1;390;/
2020-02;/dev/hd1;360;/
2020-01;/dev/hd1;300;/

---------- hd2.txt: ----------

2020-03;/dev/hd2;720;/usr
2020-02;/dev/hd2;690;/usr
2020-01;/dev/hd2;600;/usr

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

create file .txt

hi.i want to create a bash script called countfiles.sh, that will count the pack of files under the current file that their term satisfy a specific pattern. The script must show the total per file or on the whole. thank tou (4 Replies)
Discussion started by: battaglia
4 Replies

2. Shell Programming and Scripting

how to create file.txt and add current date in file content

Hey guy, how to make bash script to create foo.txt file and add current date into file content and that file always append. example: today the script run and add today date into content foo.txt and tomorrow the script will run and add tomorrow date in content foo.txt without remove today... (3 Replies)
Discussion started by: chenboly
3 Replies

3. Shell Programming and Scripting

Loop difficulty

hi all I am new to unix and want to create a loop to repeat the loop and before that it ask me to do so.I know "while" may help but I put it in my work and getting stuk with it.any help appreciated. (13 Replies)
Discussion started by: samsami1971
13 Replies

4. Shell Programming and Scripting

bash script to create txt files based on timestamp

Hi , please guide me for a bash script that will create a txt files and the name of the txt files will be as of timestamp so that each file name will be different from other and these files will be get created say after every 10 minutes in a folder(/home/p2000/sxs137), please guide me how would... (1 Reply)
Discussion started by: nks342
1 Replies

5. Shell Programming and Scripting

create txt file form data file and add some line on it

Hi Guys, I have file A.txt File A Data AK1521 AK2536 AK3164 I want create text file of all data above and write some data on each file. want Output on below folder /home/kka/out AK1521.txt Hi Welocme (3 Replies)
Discussion started by: asavaliya
3 Replies

6. Shell Programming and Scripting

How to create .txt file by using function?

My Calling script is like below: for file in `echo $LIST_OF_FILES` --listing filenames eg, xyz_meta_20110501_00000789.tar do file_name=`basename $file` <call a function to create .txt file in below format> done Want to generate a .txt file that contains below data in ksh: ... (3 Replies)
Discussion started by: vedanta
3 Replies

7. UNIX for Dummies Questions & Answers

How to create a .csv file from 2 different .txt files?

Hi, I need to create a .csv file from information that i have in two different tab delimited .txt file. I just want to select some of the columns of each .txt file and paste them into a .cvs file. My files look like: File 1 transcript_id Seq. Description Seq. Length ... (2 Replies)
Discussion started by: alisrpp
2 Replies

8. Shell Programming and Scripting

Bash/awk and for loop to create a template

Source File: google.cz http://czechrepublic.google.com/ http://czechrepublic.google.cz http://czechrepublic.google.com/ http://brno.google.cz http://brno.google.com/ Fail Code root@arisvm ~/g] $ cat trya rm -f ss for i in a.txt do #b=`cat $i|awk '{print $1}'` #c=`cat $i|awk '{print... (4 Replies)
Discussion started by: invinzin21
4 Replies

9. Shell Programming and Scripting

awk to create variables to pass into a bash loop to create a download link

I have created one file that contains all the necessary info in it to create a download link. In each of the lines /results/analysis/output/Home/Auto_user_S5-00580-6-Medexome_67_032/plugin_out/FileExporter_out.67... (8 Replies)
Discussion started by: cmccabe
8 Replies

10. UNIX for Beginners Questions & Answers

Copy the content from txt file and create a html file

I have a txt file with a list of error messages in a xml tag format, and each error message is separated with a identifier(endresult).Need to split that and copy and create a new html file.Error message has some special character. how to escape the special character and insert my data into the... (7 Replies)
Discussion started by: DevAakash
7 Replies
HD(4)							     Kernel Interfaces Manual							     HD(4)

NAME
hd - winchester hard disk DESCRIPTION
The hd* family of devices refer to the Winchester hard disk drivers for the IBM XT, AT and PS/2 machines, but may also refer to the generic (and slower) BIOS based hard disk driver. These disks are arrays of 512 byte sectors, although Minix always works with two sectors at a time due to its 1024 byte block size. You can read or write any number of bytes however, Minix takes care of cutting and pasting incom- plete blocks together. The devices may be divided into three classes: The devices with a minor device number that is a multiple of 5, i.e. hd0 or hd5, refer to the whole hard disk 0 and 1. Through these devices one has access to any block on the hard disk. Most notably the partition table, that can be found in the first sector of the disk. The devices with a minor device number that is not a multiple of 5, i.e. hd1, hd2, ..., hd6, ..., refer to primary partitions of the lower numbered whole hard disk device. These devices normally contain MS-DOS or Minix file systems. /dev/hd1 is often the MS- DOS C: drive. Minor devices from 128 up may refer to Minix subpartitions within primary partitions if a subpartition table has been placed in a Minix primary partition. The subpartitions of hd3 for instance, are named hd3a through hd3d. Their minor device numbers may be calculated as 128 + 16*drive + 4*partition + subpartition, counting the partitions from zero. If a primary partition is an extended partition then up to four logical partitions can be accessed as subpartitions of that extended partition. This allows one to access foreign file systems of other operating systems, Minix file systems are not normally placed in logical partitions. PARTITIONING
The first sector of a drive (or partition for subpartitioning) contains the partition table at byte offset 446. This is what each of the four entries looks like as defined in <ibm/partition.h>: /* Description of entry in the partition table. */ struct part_entry { unsigned char bootind; /* boot indicator 0/ACTIVE_FLAG */ unsigned char start_head; /* head value for first sector */ unsigned char start_sec; /* sector value + high 2 cyl bits */ unsigned char start_cyl; /* low 8 cylinder bits */ unsigned char sysind; /* system indicator */ unsigned char last_head; /* h/s/c for the last sector */ unsigned char last_sec; unsigned char last_cyl; unsigned long lowsec; /* logical first sector */ unsigned long size; /* size of partition in sectors */ }; #define ACTIVE_FLAG 0x80 /* value for active in bootind field */ #define NR_PARTITIONS 4 /* number of entries in table */ #define PART_TABLE_OFF 0x1BE /* offset of table in boot sector */ /* Partition types (sysind). */ #define MINIX_PART 0x81 /* Minix partition type */ #define NO_PART 0x00 /* unused entry */ #define OLD_MINIX_PART 0x80 /* created before 1.4b, obsolete */ #define EXT_PART 0x05 /* extended partition */ The cylinder numbers are encoded in a very strange way, bits 8 and 9 are in the high two bits of the sector number. The sector numbers count from 1, not 0! More useful are the lowsec and size fields however, they simply give the location of the partition as an absolute sector offset and length within the drive. The partition table entry defined above is specific to IBM type disks. The device drivers use another partition entry structure to pass information on a partition. This is what <minix/partition.h> looks like: struct partition { u64_t base; /* byte offset to the partition start */ u64_t size; /* number of bytes in the partition */ unsigned cylinders; /* disk geometry for partitioning */ unsigned heads; unsigned sectors; }; The base and size fields are the byte offset and length of a partition. (These are 64 bit numbers under Minix-vmd, but only 32 bit numbers under standard Minix.) The geometry of the disk is also given for the benefit of partition table editors. This information can be obtained from an open disk device with the call: ioctl(fd, DIOCGETP, &entry); One can change the placement of the device to the lowsec and size fields of entry by using the DIOCSETP call instead. Only the base and size fields are used for DIOCSETP. The partition tables when read from disk by the driver are checked and truncated to fit within the primary partition or drive. The first sector should be left free for the partition table. The partition tables are read when the in-use count (opens and mounts) changes from 0 to 1. So an idle disk is automatically repartitioned on the next access. This means that repartitioning programs only have effect if a disk stays in use, unless they reload a changed parti- tion table. FILES
/dev/hd[0-9], /dev/hd[1-46-9][a-d] SEE ALSO
ioctl(2), int64(3), part(8), repartition(8). BUGS
The subpartitioning is incompatible with the MS-DOS method of extended partitions. The latter does not map well to the sparse minor device number space. The primary partition table is sorted by lowsec like MS-DOS does, subpartition tables are not. Just think about what happens when you delete a partition in the MS-DOS scheme. Don't move a partition that is mounted or kept open by some process. The file system may write cached blocks to the new location. The BIOS driver is not slow at all on a buffered disk. Some IDE disks send an interrupt when they spin down under hardware power management. The driver acknowledges the interrupt as it is sup- posed to do by reading the status register. The disk then spins up again... You have to disable the spin down in the computer setup to fix the problem. AUTHOR
Kees J. Bot (kjb@cs.vu.nl) HD(4)
All times are GMT -4. The time now is 07:21 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy