bash script looping two functions
Clash Royale CLAN TAG#URR8PPP
up vote
-1
down vote
favorite
I would like to order the 5th column by highest value and select the 4th if it matches the 5th column.
cat TABLE_LIST
C1 C2 C3 C4 C5 C6
3 No ENCRYPTION /opt/oracle/oradata/ORCLCDB/encryption.dbf 8 0
2 No RETENTION /opt/oracle/oradata/ORCLCDB/retention.dbf 5 0
4 No ORACLE /opt/oracle/oradata/ORCLCDB/oracle.dbf 2 0
1 No USERS /opt/oracle/oradata/ORCLCDB/users01.dbf 3 0`
It should look like this.
for file in $C5; do
select $C4 from from dual;
done
select /opt/oracle/oradata/ORCLCDB/users01.dbf from dual;
select /opt/oracle/oradata/ORCLCDB/retention.dbf from dual;
select /opt/oracle/oradata/ORCLCDB/oracle.dbf from dual;
select /opt/oracle/oradata/ORCLCDB/encryption.dbf from dual;`
What I have tried so far is working but it read the output according to the value of C1, but I want to read according to C5, highest to lowest.
for (( x=1; x <= $FILE_COUNT; x++)) ; do
FILE_NAME=cat $TABLE_LIST|sort -rk5 |awk -vx="$x" '$1 == x print $4 $3 == x print $1'
FILE_SIZE=cat $TABLE_LIST|sort -rk5 |awk -vx="$x" '$1 == x print $5 $3 == x print $1'
done
Thanks!
awk sed for
add a comment |
up vote
-1
down vote
favorite
I would like to order the 5th column by highest value and select the 4th if it matches the 5th column.
cat TABLE_LIST
C1 C2 C3 C4 C5 C6
3 No ENCRYPTION /opt/oracle/oradata/ORCLCDB/encryption.dbf 8 0
2 No RETENTION /opt/oracle/oradata/ORCLCDB/retention.dbf 5 0
4 No ORACLE /opt/oracle/oradata/ORCLCDB/oracle.dbf 2 0
1 No USERS /opt/oracle/oradata/ORCLCDB/users01.dbf 3 0`
It should look like this.
for file in $C5; do
select $C4 from from dual;
done
select /opt/oracle/oradata/ORCLCDB/users01.dbf from dual;
select /opt/oracle/oradata/ORCLCDB/retention.dbf from dual;
select /opt/oracle/oradata/ORCLCDB/oracle.dbf from dual;
select /opt/oracle/oradata/ORCLCDB/encryption.dbf from dual;`
What I have tried so far is working but it read the output according to the value of C1, but I want to read according to C5, highest to lowest.
for (( x=1; x <= $FILE_COUNT; x++)) ; do
FILE_NAME=cat $TABLE_LIST|sort -rk5 |awk -vx="$x" '$1 == x print $4 $3 == x print $1'
FILE_SIZE=cat $TABLE_LIST|sort -rk5 |awk -vx="$x" '$1 == x print $5 $3 == x print $1'
done
Thanks!
awk sed for
It's unclear what the output should be for the given input.
– Kusalananda
Nov 26 at 21:31
I just want to grab the values of column C4 order by C5 (highest to lowest).
– Kwa Arboncana
Nov 26 at 21:44
1
Your sample outputselect /opt/oracle...
lines aren't sorted by C5 descending...
– Jeff Schaller
Nov 26 at 22:25
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I would like to order the 5th column by highest value and select the 4th if it matches the 5th column.
cat TABLE_LIST
C1 C2 C3 C4 C5 C6
3 No ENCRYPTION /opt/oracle/oradata/ORCLCDB/encryption.dbf 8 0
2 No RETENTION /opt/oracle/oradata/ORCLCDB/retention.dbf 5 0
4 No ORACLE /opt/oracle/oradata/ORCLCDB/oracle.dbf 2 0
1 No USERS /opt/oracle/oradata/ORCLCDB/users01.dbf 3 0`
It should look like this.
for file in $C5; do
select $C4 from from dual;
done
select /opt/oracle/oradata/ORCLCDB/users01.dbf from dual;
select /opt/oracle/oradata/ORCLCDB/retention.dbf from dual;
select /opt/oracle/oradata/ORCLCDB/oracle.dbf from dual;
select /opt/oracle/oradata/ORCLCDB/encryption.dbf from dual;`
What I have tried so far is working but it read the output according to the value of C1, but I want to read according to C5, highest to lowest.
for (( x=1; x <= $FILE_COUNT; x++)) ; do
FILE_NAME=cat $TABLE_LIST|sort -rk5 |awk -vx="$x" '$1 == x print $4 $3 == x print $1'
FILE_SIZE=cat $TABLE_LIST|sort -rk5 |awk -vx="$x" '$1 == x print $5 $3 == x print $1'
done
Thanks!
awk sed for
I would like to order the 5th column by highest value and select the 4th if it matches the 5th column.
cat TABLE_LIST
C1 C2 C3 C4 C5 C6
3 No ENCRYPTION /opt/oracle/oradata/ORCLCDB/encryption.dbf 8 0
2 No RETENTION /opt/oracle/oradata/ORCLCDB/retention.dbf 5 0
4 No ORACLE /opt/oracle/oradata/ORCLCDB/oracle.dbf 2 0
1 No USERS /opt/oracle/oradata/ORCLCDB/users01.dbf 3 0`
It should look like this.
for file in $C5; do
select $C4 from from dual;
done
select /opt/oracle/oradata/ORCLCDB/users01.dbf from dual;
select /opt/oracle/oradata/ORCLCDB/retention.dbf from dual;
select /opt/oracle/oradata/ORCLCDB/oracle.dbf from dual;
select /opt/oracle/oradata/ORCLCDB/encryption.dbf from dual;`
What I have tried so far is working but it read the output according to the value of C1, but I want to read according to C5, highest to lowest.
for (( x=1; x <= $FILE_COUNT; x++)) ; do
FILE_NAME=cat $TABLE_LIST|sort -rk5 |awk -vx="$x" '$1 == x print $4 $3 == x print $1'
FILE_SIZE=cat $TABLE_LIST|sort -rk5 |awk -vx="$x" '$1 == x print $5 $3 == x print $1'
done
Thanks!
awk sed for
awk sed for
edited Nov 26 at 21:45
Kulfy
1032
1032
asked Nov 26 at 21:26
Kwa Arboncana
33
33
It's unclear what the output should be for the given input.
– Kusalananda
Nov 26 at 21:31
I just want to grab the values of column C4 order by C5 (highest to lowest).
– Kwa Arboncana
Nov 26 at 21:44
1
Your sample outputselect /opt/oracle...
lines aren't sorted by C5 descending...
– Jeff Schaller
Nov 26 at 22:25
add a comment |
It's unclear what the output should be for the given input.
– Kusalananda
Nov 26 at 21:31
I just want to grab the values of column C4 order by C5 (highest to lowest).
– Kwa Arboncana
Nov 26 at 21:44
1
Your sample outputselect /opt/oracle...
lines aren't sorted by C5 descending...
– Jeff Schaller
Nov 26 at 22:25
It's unclear what the output should be for the given input.
– Kusalananda
Nov 26 at 21:31
It's unclear what the output should be for the given input.
– Kusalananda
Nov 26 at 21:31
I just want to grab the values of column C4 order by C5 (highest to lowest).
– Kwa Arboncana
Nov 26 at 21:44
I just want to grab the values of column C4 order by C5 (highest to lowest).
– Kwa Arboncana
Nov 26 at 21:44
1
1
Your sample output
select /opt/oracle...
lines aren't sorted by C5 descending...– Jeff Schaller
Nov 26 at 22:25
Your sample output
select /opt/oracle...
lines aren't sorted by C5 descending...– Jeff Schaller
Nov 26 at 22:25
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
According to comments you want to list the 4th column in the order dictated by the 5th column (in reverse numerical order).
$ sed '1d' <TABLE_LIST | sort -k5,5nr | awk ' print $4 '
/opt/oracle/oradata/ORCLCDB/encryption.dbf
/opt/oracle/oradata/ORCLCDB/retention.dbf
/opt/oracle/oradata/ORCLCDB/users01.dbf
/opt/oracle/oradata/ORCLCDB/oracle.dbf
The sed
command strips the header from the file and the sort
sorts the remaining lines on the 5th column in decreasing numerical order. The final awk
extracts the 4th column.
This would work as long as none of the columns contained a whitespace character within the column itself.
Would you want to insert those select
and from dual;
strings, then you could modify the awk
part of the pipeline:
$ sed '1d' <TABLE_LIST | sort -k5,5nr | awk ' printf("select %s from dual;n", $4) '
select /opt/oracle/oradata/ORCLCDB/encryption.dbf from dual;
select /opt/oracle/oradata/ORCLCDB/retention.dbf from dual;
select /opt/oracle/oradata/ORCLCDB/users01.dbf from dual;
select /opt/oracle/oradata/ORCLCDB/oracle.dbf from dual;
This is perfect!! Thanks a lot @kusalananda it worked!!
– Kwa Arboncana
Nov 26 at 22:56
add a comment |
up vote
0
down vote
Using GNU Awk > 4.0
gawk '
FNR>1 a[$5] = $4
END
PROCINFO["sorted_in"] = "@ind_num_desc";
for (i in a) print "select " a[i] " from dual;"
' TABLE_LIST
select /opt/oracle/oradata/ORCLCDB/encryption.dbf from dual;
select /opt/oracle/oradata/ORCLCDB/retention.dbf from dual;
select /opt/oracle/oradata/ORCLCDB/users01.dbf from dual;
select /opt/oracle/oradata/ORCLCDB/oracle.dbf from dual;
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
According to comments you want to list the 4th column in the order dictated by the 5th column (in reverse numerical order).
$ sed '1d' <TABLE_LIST | sort -k5,5nr | awk ' print $4 '
/opt/oracle/oradata/ORCLCDB/encryption.dbf
/opt/oracle/oradata/ORCLCDB/retention.dbf
/opt/oracle/oradata/ORCLCDB/users01.dbf
/opt/oracle/oradata/ORCLCDB/oracle.dbf
The sed
command strips the header from the file and the sort
sorts the remaining lines on the 5th column in decreasing numerical order. The final awk
extracts the 4th column.
This would work as long as none of the columns contained a whitespace character within the column itself.
Would you want to insert those select
and from dual;
strings, then you could modify the awk
part of the pipeline:
$ sed '1d' <TABLE_LIST | sort -k5,5nr | awk ' printf("select %s from dual;n", $4) '
select /opt/oracle/oradata/ORCLCDB/encryption.dbf from dual;
select /opt/oracle/oradata/ORCLCDB/retention.dbf from dual;
select /opt/oracle/oradata/ORCLCDB/users01.dbf from dual;
select /opt/oracle/oradata/ORCLCDB/oracle.dbf from dual;
This is perfect!! Thanks a lot @kusalananda it worked!!
– Kwa Arboncana
Nov 26 at 22:56
add a comment |
up vote
1
down vote
accepted
According to comments you want to list the 4th column in the order dictated by the 5th column (in reverse numerical order).
$ sed '1d' <TABLE_LIST | sort -k5,5nr | awk ' print $4 '
/opt/oracle/oradata/ORCLCDB/encryption.dbf
/opt/oracle/oradata/ORCLCDB/retention.dbf
/opt/oracle/oradata/ORCLCDB/users01.dbf
/opt/oracle/oradata/ORCLCDB/oracle.dbf
The sed
command strips the header from the file and the sort
sorts the remaining lines on the 5th column in decreasing numerical order. The final awk
extracts the 4th column.
This would work as long as none of the columns contained a whitespace character within the column itself.
Would you want to insert those select
and from dual;
strings, then you could modify the awk
part of the pipeline:
$ sed '1d' <TABLE_LIST | sort -k5,5nr | awk ' printf("select %s from dual;n", $4) '
select /opt/oracle/oradata/ORCLCDB/encryption.dbf from dual;
select /opt/oracle/oradata/ORCLCDB/retention.dbf from dual;
select /opt/oracle/oradata/ORCLCDB/users01.dbf from dual;
select /opt/oracle/oradata/ORCLCDB/oracle.dbf from dual;
This is perfect!! Thanks a lot @kusalananda it worked!!
– Kwa Arboncana
Nov 26 at 22:56
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
According to comments you want to list the 4th column in the order dictated by the 5th column (in reverse numerical order).
$ sed '1d' <TABLE_LIST | sort -k5,5nr | awk ' print $4 '
/opt/oracle/oradata/ORCLCDB/encryption.dbf
/opt/oracle/oradata/ORCLCDB/retention.dbf
/opt/oracle/oradata/ORCLCDB/users01.dbf
/opt/oracle/oradata/ORCLCDB/oracle.dbf
The sed
command strips the header from the file and the sort
sorts the remaining lines on the 5th column in decreasing numerical order. The final awk
extracts the 4th column.
This would work as long as none of the columns contained a whitespace character within the column itself.
Would you want to insert those select
and from dual;
strings, then you could modify the awk
part of the pipeline:
$ sed '1d' <TABLE_LIST | sort -k5,5nr | awk ' printf("select %s from dual;n", $4) '
select /opt/oracle/oradata/ORCLCDB/encryption.dbf from dual;
select /opt/oracle/oradata/ORCLCDB/retention.dbf from dual;
select /opt/oracle/oradata/ORCLCDB/users01.dbf from dual;
select /opt/oracle/oradata/ORCLCDB/oracle.dbf from dual;
According to comments you want to list the 4th column in the order dictated by the 5th column (in reverse numerical order).
$ sed '1d' <TABLE_LIST | sort -k5,5nr | awk ' print $4 '
/opt/oracle/oradata/ORCLCDB/encryption.dbf
/opt/oracle/oradata/ORCLCDB/retention.dbf
/opt/oracle/oradata/ORCLCDB/users01.dbf
/opt/oracle/oradata/ORCLCDB/oracle.dbf
The sed
command strips the header from the file and the sort
sorts the remaining lines on the 5th column in decreasing numerical order. The final awk
extracts the 4th column.
This would work as long as none of the columns contained a whitespace character within the column itself.
Would you want to insert those select
and from dual;
strings, then you could modify the awk
part of the pipeline:
$ sed '1d' <TABLE_LIST | sort -k5,5nr | awk ' printf("select %s from dual;n", $4) '
select /opt/oracle/oradata/ORCLCDB/encryption.dbf from dual;
select /opt/oracle/oradata/ORCLCDB/retention.dbf from dual;
select /opt/oracle/oradata/ORCLCDB/users01.dbf from dual;
select /opt/oracle/oradata/ORCLCDB/oracle.dbf from dual;
edited Nov 26 at 22:03
answered Nov 26 at 21:51
Kusalananda
118k16223364
118k16223364
This is perfect!! Thanks a lot @kusalananda it worked!!
– Kwa Arboncana
Nov 26 at 22:56
add a comment |
This is perfect!! Thanks a lot @kusalananda it worked!!
– Kwa Arboncana
Nov 26 at 22:56
This is perfect!! Thanks a lot @kusalananda it worked!!
– Kwa Arboncana
Nov 26 at 22:56
This is perfect!! Thanks a lot @kusalananda it worked!!
– Kwa Arboncana
Nov 26 at 22:56
add a comment |
up vote
0
down vote
Using GNU Awk > 4.0
gawk '
FNR>1 a[$5] = $4
END
PROCINFO["sorted_in"] = "@ind_num_desc";
for (i in a) print "select " a[i] " from dual;"
' TABLE_LIST
select /opt/oracle/oradata/ORCLCDB/encryption.dbf from dual;
select /opt/oracle/oradata/ORCLCDB/retention.dbf from dual;
select /opt/oracle/oradata/ORCLCDB/users01.dbf from dual;
select /opt/oracle/oradata/ORCLCDB/oracle.dbf from dual;
add a comment |
up vote
0
down vote
Using GNU Awk > 4.0
gawk '
FNR>1 a[$5] = $4
END
PROCINFO["sorted_in"] = "@ind_num_desc";
for (i in a) print "select " a[i] " from dual;"
' TABLE_LIST
select /opt/oracle/oradata/ORCLCDB/encryption.dbf from dual;
select /opt/oracle/oradata/ORCLCDB/retention.dbf from dual;
select /opt/oracle/oradata/ORCLCDB/users01.dbf from dual;
select /opt/oracle/oradata/ORCLCDB/oracle.dbf from dual;
add a comment |
up vote
0
down vote
up vote
0
down vote
Using GNU Awk > 4.0
gawk '
FNR>1 a[$5] = $4
END
PROCINFO["sorted_in"] = "@ind_num_desc";
for (i in a) print "select " a[i] " from dual;"
' TABLE_LIST
select /opt/oracle/oradata/ORCLCDB/encryption.dbf from dual;
select /opt/oracle/oradata/ORCLCDB/retention.dbf from dual;
select /opt/oracle/oradata/ORCLCDB/users01.dbf from dual;
select /opt/oracle/oradata/ORCLCDB/oracle.dbf from dual;
Using GNU Awk > 4.0
gawk '
FNR>1 a[$5] = $4
END
PROCINFO["sorted_in"] = "@ind_num_desc";
for (i in a) print "select " a[i] " from dual;"
' TABLE_LIST
select /opt/oracle/oradata/ORCLCDB/encryption.dbf from dual;
select /opt/oracle/oradata/ORCLCDB/retention.dbf from dual;
select /opt/oracle/oradata/ORCLCDB/users01.dbf from dual;
select /opt/oracle/oradata/ORCLCDB/oracle.dbf from dual;
answered Nov 27 at 0:46
steeldriver
33.8k34983
33.8k34983
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f484304%2fbash-script-looping-two-functions%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
It's unclear what the output should be for the given input.
– Kusalananda
Nov 26 at 21:31
I just want to grab the values of column C4 order by C5 (highest to lowest).
– Kwa Arboncana
Nov 26 at 21:44
1
Your sample output
select /opt/oracle...
lines aren't sorted by C5 descending...– Jeff Schaller
Nov 26 at 22:25