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
Commands Reference, Volume 2, d - h

fuser_Command

  Purpose

   Identifies processes using a file or file structure.

  Syntax

   fuser [ -c | -d | -f ] [ -k | -K { SignalNumber |
   SignalName }] [ -u ] [ -x ] [ -V ]File ...

  Description

   The fuser command lists the process numbers of local processes
that use
   the local or remote files specified by the File parameter. For
block
   special  devices, the command lists the processes that use any
file on that
   device.

   Each process number is followed by a letter indicating how the
process
   uses the file:

   c	   Uses the file as the current directory.
   e	   Uses the file as a program's executable object.
   r	   Uses the file as the root directory.
   s	    Uses  the file as a shared library (or other loadable
object).

   The process numbers are written to standard output in  a  line
with spaces
   between  process  numbers.  A new line character is written to
standard error
   after the last output for each file operand. All other  output
is written
   to standard error.

   The fuser command will not detect processes that have mmap re-
gions where
   that associated file descriptor has since been closed.

  Flags

   -c		     Reports on any open files in the file system
containing
		     File.
		     Implies  the use of the -c and -x flags. Re-
ports on any
		     open files which have been unlinked from the
file system
   -d		      (deleted	from  the parent directory). When
used in
		     conjunction with the -V flag,  it	also  re-
ports the inode
		     number and size of the deleted file.
   -f		     Reports on open instances of File only.
		     Sends  the  specified  signal  to each local
process. Only
   -K SignalNumber | the root user can kill a process of  another
user. Signal
   SignalName	      can  be  specified as either a signal name,
such as -9 or
		     KILL for the SIGKILL  signal.  Valid  values
for SignalName
		     are those which are displayed by the kill -l
command.
		     Sends  the  SIGKILL  signal  to  each  local
process. Only the
		     root  user can kill a process of another us-
er.
   -k		     Note:
		     fuser -k or -K might not be able  to  detect
and kill new
		     processes that are created immediately after
the program
		     starts to run.
   -u		     Provides the login name for local	processes
in
		     parentheses after the process number.
   -V		     Provides verbose output.
		     Used  in  conjunction with -c or -f, reports
on executable
   -x		     and loadable  objects  in	addition  to  the
standard fuser
		     output.

  Examples

    1.	To  list the process numbers of local processes using the
/etc/passwd
       file, enter:

	 fuser /etc/passwd

    2. To list the process numbers and user login names  of  pro-
cesses using
       the /etc/filesystems file, enter:

	 fuser -u /etc/filesystems

    3.	To terminate all of the processes using a given file sys-
tem, enter:

	 fuser -k -x -u -c /dev/hd1

       or

	 fuser -kxuc /home

       Either command lists the process number and user name, and
then
       terminates each process that is using the /dev/hd1 (/home)
file
       system. Only the root user can  terminate  processes  that
belong to
       another	user.  You  might want to use this command if you
are trying to
       unmount the /dev/hd1 file system and a process that is ac-
cessing the
       /dev/hd1 file system prevents this.

    4. To list all processes that are using a file which has been
deleted
       from a given file system, enter:

	 fuser -d /usr

  Files

   /dev/kmem		      Used for the system image.
   /dev/mem		      Also used for the system image.

  Related Information

   The kill command, killall command, mount command, and ps
   command.

   For more information about the identification and  authentica-
tion of users,
   discretionary  access control, the trusted computing base, and
auditing,
   refer to Security.

________________________________________________________________________________

		      Commands Reference, Volume 2, d - h

fuser_Command

  Purpose

   Identifies processes using a file or file structure.

  Syntax

   fuser [ -c | -d | -f ] [ -k | -K { SignalNumber |
   SignalName }] [ -u ] [ -x ] [ -V ]File ...

  Description

   The fuser command lists the process numbers of local processes
that use
   the local or remote files specified by the File parameter. For
block
   special  devices, the command lists the processes that use any
file on that
   device.

   Each process number is followed by a letter indicating how the
process
   uses the file:

   c	   Uses the file as the current directory.
   e	   Uses the file as a program's executable object.
   r	   Uses the file as the root directory.
   s	    Uses  the file as a shared library (or other loadable
object).

   The process numbers are written to standard output in  a  line
with spaces
   between  process  numbers.  A new line character is written to
standard error
   after the last output for each file operand. All other  output
is written
   to standard error.

   The fuser command will not detect processes that have mmap re-
gions where
   that associated file descriptor has since been closed.

  Flags

   -c		     Reports on any open files in the file system
containing
		     File.
		     Implies  the use of the -c and -x flags. Re-
ports on any
		     open files which have been unlinked from the
file system
   -d		      (deleted	from  the parent directory). When
used in
		     conjunction with the -V flag,  it	also  re-
ports the inode
		     number and size of the deleted file.
   -f		     Reports on open instances of File only.
		     Sends  the  specified  signal  to each local
process. Only
   -K SignalNumber | the root user can kill a process of  another
user. Signal
   SignalName	      can  be  specified as either a signal name,
such as -9 or
		     KILL for the SIGKILL  signal.  Valid  values
for SignalName
		     are those which are displayed by the kill -l
command.
		     Sends  the  SIGKILL  signal  to  each  local
process. Only the
		     root  user can kill a process of another us-
er.
   -k		     Note:
		     fuser -k or -K might not be able  to  detect
and kill new
		     processes that are created immediately after
the program
		     starts to run.
   -u		     Provides the login name for local	processes
in
		     parentheses after the process number.
   -V		     Provides verbose output.
		     Used  in  conjunction with -c or -f, reports
on executable
   -x		     and loadable  objects  in	addition  to  the
standard fuser
		     output.

  Examples

    1.	To  list the process numbers of local processes using the
/etc/passwd
       file, enter:

	 fuser /etc/passwd

    2. To list the process numbers and user login names  of  pro-
cesses using
       the /etc/filesystems file, enter:

	 fuser -u /etc/filesystems

    3.	To terminate all of the processes using a given file sys-
tem, enter:

	 fuser -k -x -u -c /dev/hd1

       or

	 fuser -kxuc /home

       Either command lists the process number and user name, and
then
       terminates each process that is using the /dev/hd1 (/home)
file
       system. Only the root user can  terminate  processes  that
belong to
       another	user.  You  might want to use this command if you
are trying to
       unmount the /dev/hd1 file system and a process that is ac-
cessing the
       /dev/hd1 file system prevents this.

    4. To list all processes that are using a file which has been
deleted
       from a given file system, enter:

	 fuser -d /usr

  Files

   /dev/kmem		      Used for the system image.
   /dev/mem		      Also used for the system image.

  Related Information

   The kill command, killall command, mount command, and ps
   command.

   For more information about the identification and  authentica-
tion of users,
   discretionary  access control, the trusted computing base, and
auditing,
   refer to Security.
All times are GMT -4. The time now is 07:10 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy