Running bash script
1
0
Entering edit mode
2.9 years ago

Hi everyone, How can I run a loop similar to this regardless of the order of the listed commands.

for file in 
do
  head -n 2 $filename | tail -n 1
done

I would appreciate any recommendation and thanks in advance.

bash • 1.0k views
ADD COMMENT
1
Entering edit mode

What do you mean when you say regardless of the order of the commands?

ADD REPLY
0
Entering edit mode

I mean I need to run a similar script by using variables equivalent to tail, head and file name. But the user can insert them in any order and it will run the script correctly according to the user needs. I can provide the user key or guide to guide them how to use the script.

ADD REPLY
0
Entering edit mode

similar to this loop

  -h 19 -f file name -t 3 

but the user type it in any order.

ADD REPLY
1
Entering edit mode
2.9 years ago
Mensur Dlakic ★ 28k

Copy this into myscript.sh and run bash myscript.sh. You will need to replace *.fastq with whatever satisfies your conditions.

#!/bin/bash
for file in *.fastq
do
head -n 2 $file | tail -n 1
done
ADD COMMENT

Login before adding your answer.

Traffic: 1199 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6