Sponsored Content
Top Forums Shell Programming and Scripting How to use a loop for multiple files in a folder to run awk command? Post 302940849 by sajmar on Thursday 9th of April 2015 12:31:28 PM
Old 04-09-2015
How to use a loop for multiple files in a folder to run awk command?

Dear folks

I have two data set which there names are "final.map" and "1.geno" and look like this structures:
final.map:
Code:
gi|358485511|ref|NC_006088.3| 2044
 
 gi|358485511|ref|NC_006088.3| 2048
 gi|358485511|ref|NC_006088.3| 2187
 gi|358485511|ref|NC_006088.3| 17654
 
 gi|358485511|ref|NC_006088.3| 17666


1.geno:
Code:
gi|358485511|ref|NC_006088.3| 2048   G C 0 1 1
 gi|358485511|ref|NC_006088.3| 17654 A G 1 1 2
 
 gi|358485511|ref|NC_006088.3| 17666 A G 0 1 1
 
 gi|358485511|ref|NC_006088.3| 17785 G A 0 1 1
 gi|358485511|ref|NC_006088.3| 30347 G C 1 1 2


Now, I am trying to run this command below:

Code:
awk -f example.awk 1.geno final.map > 1.dat


In this command "example.awk" contains the below command:
NR==FNR{a[$1,$2]=$5" "$6" "$7;next}{print $1,$2,a[$1,$2]?a[$1,$2]:"0 0 0"}


the output of the awk command give us "1.dat" which is
Code:
gi|358485511|ref|NC_006088.3| 2044   0 0 0
 
gi|358485511|ref|NC_006088.3| 2048   0 1 1
 
 gi|358485511|ref|NC_006088.3| 2187   0 0 0
 
 gi|358485511|ref|NC_006088.3| 17654 1 1 2
 
 gi|358485511|ref|NC_006088.3| 17666 0 1 1




My problem is I have around 300 *.geno files which I want to get *.dat out of the awk command. I am knowing the loop in unix could be helpful but I think I am using the loop wrong in some way.

Could any one give me an idea how to avoid to run awk each time separately and do it at one time by looping?

Last edited by vgersh99; 04-09-2015 at 02:07 PM.. Reason: code tags, please!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to run awk command having multiple lines

Hi, Can u see the code below. set xyz = `cat testt1.txt | awk '/-----/{\ print $1 }\ ' | tail -1` I need to execute it in c shell . What is wrong with the above command. When i write everything on a single line then it is working. Can anybody help me . (0 Replies)
Discussion started by: nani_g
0 Replies

2. UNIX for Dummies Questions & Answers

Foreach loop to run a perl script on multiple files

Hi, I have thousands of files in a directory that have the following 2 formats: 289620178.aln 289620179.aln 289620180.aln 289620183.aln 289620184.aln 289620185.aln 289620186.aln 289620187.aln 289620188.aln 289620189.aln 289620190.aln 289620192.aln.... and: alnCDS_1.fasta (1 Reply)
Discussion started by: greptastic
1 Replies

3. Shell Programming and Scripting

How to run multiple awk files

I'm trying some thing like this. But not working It worked for bash files Now I want some thing like that along with multiple input files by redirecting their outputs as inputs of next command like below Could you guyz p0lz help me on this #!/usr/bin/awk -f BEGIN { } script1a.awk... (2 Replies)
Discussion started by: repinementer
2 Replies

4. Shell Programming and Scripting

using mv command for moving multiple files in a folder

Hi, I have a requirement where I need to move Bunch of folders containing multiple files to another archive location. i want to use mv command .I am thinking when we use mv command to move directory does it create directory 1st and then move all the files ? e.g source... (4 Replies)
Discussion started by: rkmbcbs
4 Replies

5. Shell Programming and Scripting

Receiving 'ambiguous redirect' when trying to run command against multiple files

I came across the command string on https://www.unix.com/shell-programming-scripting/141885-awk-removing-data-before-after-pattern.html which was what I was looking for to be able to remove data before a certain pattern. However, outputting the result to a file seems to work on an individual basis... (4 Replies)
Discussion started by: HLee1981
4 Replies

6. Shell Programming and Scripting

Loop for row-wise averaging of multiple files using awk

Hello all, I need to compute a row-wise average of files with a single column based on the pattern of the filenames. I really appreciate any help on this. it would just be very difficult to do them manually as the rows are mounting to 100,000 lines. the filenames are as below with convention as... (2 Replies)
Discussion started by: ida1215
2 Replies

7. Shell Programming and Scripting

Script for telnet and run one command kill it and run another command using while loop

( sleep 3 echo ${LOGIN} sleep 2 echo ${PSWD} sleep 2 while read line do echo "$line" PID=$? sleep 2 kill -9 $PID done < temp sleep 5 echo "exit" ) | telnet ${HOST} while is executing only command and exits. (5 Replies)
Discussion started by: sooda
5 Replies

8. Shell Programming and Scripting

FOR loop with multiple files as input and awk

Hi all , i want to pass multiple files as input to a for loop for i in file1 file2 file3 do some awk action < $i >> $i.out done but im getting error in that for loop is the way i use to pass files to awk using for correct and 2.we can directly pass multiple files to awk as... (7 Replies)
Discussion started by: zozoo
7 Replies

9. UNIX for Dummies Questions & Answers

Loop awk command on files in a folder

Hi, I'd like to loop an action over all files with given extension within a folder. The "main" action is: awk -F "\t" 'BEGIN{OFS="\t"}{if ($10=="S") print$0; }' input.txt > output.txt The input.txt should be every file in the folder with *.subVCF extension; and the output should be a file... (3 Replies)
Discussion started by: dovah
3 Replies

10. Programming

Run sed and awk in multiple files in adirectory

Dear linux users I was running around of 200 djob for a Blastp search in a cluster. All my input files were protein fasta file (prot.fna.1, prot.fna.2 ...prot.fna.200). The output of each individual slurm job is located in a corresponding file ending with *test (prot.fna.1.test,... (10 Replies)
Discussion started by: Dieunel
10 Replies
rmf(1mh)																  rmf(1mh)

Name
       rmf - remove folder

Syntax
       rmf [ +folder ] [ -help ] [ -[no]interactive ]

Description
       The  command  removes all of the messages within the current folder, and then removes the folder itself.  If there are any files within the
       folder which are not part of MH, they are not removed, and an error message is displayed.

       You can specify a folder other than the current folder by using the +folder argument.  If you do not specify a folder, and cannot find  the
       current folder, asks you whether you want to delete instead.

       If the current folder is removed, it makes current.

       Note that the command irreversibly deletes messages that do not have other links, so use it with caution.

       If  the folder being removed is a sub-folder, the parent folder becomes the new current folder, and tells you that this has happened.  This
       provides an easy mechanism for selecting a set of messages, operating on the list, then removing the list  and  returning  to  the  current
       folder from which the list was extracted.

       Using to delete a read-only folder deletes the private sequence and current message information from the file, without affecting the folder
       itself.	If you have sub-folders within a folder, you must delete all the sub-folders before you can delete the folder itself.

Options
       -help	 Prints a list of the valid options to this command.

       -interactive
       -nointeractive
		 Asks for confirmation before deleting a folder.  By default, deletes a folder and its messages without asking	for  confirmation.
		 If  you  specify  the	-interactive option, asks if you are sure before deleting the folder.  You are advised to use this option,
		 since when deletes a folder its contents are lost irretrievably.

Examples
       This example shows how asks for confirmation when the -interactive option is used:
       % rmf -interactive +test
       Remove folder "test"? y

Profile Components
       Path:   To determine the user's Mail directory

Files
       The user profile.

See Also
       rmm(1mh)

																	  rmf(1mh)
All times are GMT -4. The time now is 05:53 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy